当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。