page-break

CSS page-break Property (CSS page-break属性)

In fact, there is not a page-break property in the CSS specification. It is a set of three properties: page-break-inside, page-break-before, and page-break-after. These properties define the behavior of the document when printed. None of them can be used on an empty <div> or on absolutely positioned elements.

Page-break-after

Page-break-after

The page-break-after property defines page break after the element. (Page-break-after属性定义元素后的分页符。)

The page-break-after property is replaced by break-after property. (> page-break-after属性被break-after属性替换。)

Use the code example below to define page break after the element:

@media print {
 footer {
   page-break-after: left;
 }
}

Page-break-before

Page-break-before

The page-break-before property defines page break before the element. (Page-break-before属性定义元素之前的分页符。)

The page-break-before property is replaced by break-before property. (> page-break-before属性被break-before属性替换。)

Use the code example below to define page break before the element:

@media print {
 h2 {
   page-break-before: right;
 }
}

Page-break-inside

Page-break-inside

The page-break-inside property defines the page break inside the element. (Page-break-inside属性定义元素内的分页符。)

The page-break-inside property is replaced by break-inside property. (> PAGE-BREAK-INSIDE属性被BREAK-INSIDE属性替换。)

Example of the break-inside property:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
   <style>
     .example {
       background-color: #8ebf42;
       height: 90px;
       width: 200px;
       columns: 1;
       column-width: 80px;
     }
     .list,
(名单中。)
     ol,
(ol)
     ul,
(ul)
     p {
       break-inside: avoid;
     }
     p {
       background-color: #8ebf42;
     }
     ol,
(ol)
     ul,
(ul)
     .list {
       margin: 0.5em 0;
       display: block;
       background-color: #1c87c9;
     }
     p:first-child {
       margin-top: 1;
     }
   </style>
 </head>
 <body>
   <h2>Page-break property example</h2>
   <div class="example">
     <p>The first paragraph.</p>
     <section class="list">
       <span>A list</span>
       <ol>
         <li>one</li>
       </ol>
     </section>
     <ul>
       <li>one</li>
     </ul>
     <p>The second paragraph.</p>
     <p>The third paragraph, it contains more text.</p>
     <p>The fourth paragraph. It has a little bit more text than the third one.</p>
   </div>
 </body>
</html>

Values

Values (价值)

ValueDescription
autoAutomatic page-break. This is the default value.
alwaysAlways force a page break after the element.
avoidAvoid a page-break after the element.
leftForce a page-break after the element, so that the following page is formatted as a left page.
rightForce a page-break after the element, so that the following page is formatted as a right page.
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部