Controlling Page Breaks
If you want to start a new page with each chapter title, or if you want to avoid breaking a table onto two pages or avoid a break after a section title, you can use CSS properties to control the breaks.
- page-break-before
- page-break-after
- page-break-inside
Forcing Page Breaks
To always move the content to the beginning of the page (for example, before the title of a section), you can use:
section h1 {
page-break-before: always;
}
Or if you only want a specific element to appear on a single page:
div.notice {
page-break-before: always;
page-break-after: always;
}
Avoiding Page Breaks
Sometimes page breaks should be avoided. For instance, to avoid breaking between a title and the subsequent content:
h1, h2, h3, h4, h5, h6 {
page-break-after: avoid;
}
Or if you want to avoid breaks inside tables and lists:
table, ol, ul {
page-break-inside: avoid;
}
Page Breaks Between Named Pages
A page break will be created each time there is a change in the page
property associated to the elements in a sequence. Suppose that you have a sequence of
<div>
elements, one of them associated with a "cover" page, and others with a
"chapter" page:
div.cover {
page: cover;
}
div.chapter {
page: chapter;
}
The XML document:
...
<div class="cover"> Welcome to the User Guide... </div>
<div class="chapter"> Here are the details... </div>
<div class="chapter"> Here are some more details... </div>
In this example, there will be a forced page break between the first <div>
(associated to the "cover" page) and the second because of the page
change.
<div>
elements are not separated by page breaks because they have
the same page
name ("chapter") and they are grouped in the same page
sequence. If you want to style the first page from that sequence in a different way, the
selector:@page content:first{
background-color: yellow;
}
will
apply to the first page from the first "chapter" <div>
.<div>
element. This can be done using the extension property
-oxy-page-group
:div.chapter {
page: chapter;
-oxy-page-group:start;
}
Page Breaks Between Lines: Widows and Orphans
There are cases where a page break is placed between paragraph lines. Typically, for aesthetic purposes, the first paragraph should have more than one line. Another constraint might be the number of lines that are moved to the next page and again, it should avoid leaving a single line. CSS defines two properties for this type of control:
orphans
- This property specifies the minimum number of line boxes that should be left in a paragraph before the page break occurs.widows
- This property specifies the minimum number of line boxes of a block container that must be left in a paragraph created on the next page after a break.
p {
orphans: 4;
widows: 2;
}
widows
and
orphans
CSS properties are applied to lists as well (the default is 2).
This means that a list that spans consecutive pages will have either zero or at least 2
lines on each of the pages.