當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


CSS page-break-after用法及代碼示例


CSS中的page-break-after屬性用於在指定的元素之後添加page-break。

同樣,page-break-before,page-break-after和page-break-inside這三個屬性都有助於確定並定義如何打印結果文檔。

注意:page-break-after屬性不能用於絕對定位的元素或空的<div>元素。


用法

page-break-after:auto|always|avoid|left|right|initial|inherit;

屬性值

  • auto:此值是指自動page-break。
    page-break-after:auto;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:auto 
        </title> 
    </head> 
      
    <body> 
      
        <p style= "page-break-after:auto;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
      Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • always:使用此值時,總是在指定的元素框後插入分頁符。
    page-break-after:always;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:always 
        </title> 
    </head> 
      
    <body> 
        <p style= "page-break-after:always;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        <p style= "page-break-after:always;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • avoid:使用此值時,將盡可能避免分頁符。
    page-break-after:avoid;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:avoid 
        </title> 
    </head> 
      
    <body> 
        <p style= "page-break-after:avoid;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        <p> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • left:使用此值時,將插入分頁符,以便將下一頁描繪為左頁。
    page-break-after:left;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:left 
        </title> 
    </head> 
      
    <body> 
        <p style= "page-break-after:left;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        <p> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • right:使用此值時,將插入分頁符,以便將下一頁描繪為左頁。
    page-break-after:right;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:right 
        </title> 
    </head> 
      
    <body> 
        <p style= "page-break-after:right;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        <p> 
                   The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • initial:如果使用此值,則該屬性將設置為默認值。
    page-break-after:initial;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title> 
            page-break-after:initial 
        </title> 
    </head> 
      
    <body> 
        <p style= "page-break-after:initial;"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        <p> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    
  • inherit:屬性是從父元素繼承的
    page-break-after:inherit;
    

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title>css_page_break_after</title> 
        <style> 
            p { 
                page-break-after:always; 
            } 
              
            div{ 
                page-break-after:default; 
            } 
              
            #c1{ 
                page-break-after:left; 
            } 
              
            #c2{ 
                page-break-after:inherit; 
            } 
        </style> 
    </head> 
      
    <body> 
        <p> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p> 
        <div> 
            <p id="c2"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </div> 
          
        <p id="c1"> 
            The oldest classical Greek and Latin  
            writing had little or no space between 
            words and could be written in boustrophedon 
            (alternating directions). Over time, text 
            direction (left to right) became standardized, 
            and word dividers and terminal punctuation  
            became common. The first way to divide sentences 
            into groups was the original paragraphos,  
            similar to an underscore at the beginning of 
            the new group.[2] The Greek paragraphos  
            evolved into the pilcrow, which in English  
            manuscripts in the Middle Ages can be seen  
            inserted inline between sentences. The hedera  
            leaf (e.g. ?) has also been used in the same way. 
        </p>  
          
        Text credits:https://en.wikipedia.org/wiki/Paragraph 
    </body> 
    </html>                    

注意:通過選擇給定HTML代碼的網頁的打印預覽,可以最佳地查看page-break-after屬性的結果。在文本編輯器(如notepad ++)上創建類似的代碼,然後選擇對創建的網頁進行打印預覽。請嘗試以更好地理解它。

支持的瀏覽器:下麵列出了page-break-after屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • 火狐瀏覽器
  • Opera
  • 蘋果瀏覽器


相關用法


注:本文由純淨天空篩選整理自EnaMotwani大神的英文原創作品 CSS | page-break-after Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。