Controlling Printing with CSS

The page-break-before and page-break-after CSS attributes do not modify the display of the page on the screen. Instead, they are used to control how the document prints. Each of these attributes accepts four values; auto, always, left, and right. Auto is the default, and page breaks are inserted only as needed. Setting page-break-before to always causes the printer to begin a new page whenever it reaches the specified element. A page-break-before of left causes page breaks to be inserted until the specified element appears on a blank left page. A page-break-before of right causes page breaks to be inserted until the element appears on a blank right page. The page-break-after attribute controls page breaks after the element, instead of before. Code Listing 14-4 on the following page demonstrates these attributes, and Figure 14-4 shows the display of the page on the screen.

Code Listing 14-4.

 <HTML> <HEAD> <TITLE>Listing 14-4</TITLE> </HEAD> <BODY> <DIV>This is the first DIV.</DIV> <DIV STYLE="page-break-before:always">This is the second DIV.</DIV> <DIV STYLE="page-break-after:always">This is the third DIV.</DIV> <DIV>This is the fourth DIV.</DIV> <DIV STYLE="page-break-before:right">This is the fifth DIV.</DIV> <DIV STYLE="page-break-after:right">This is the sixth DIV.</DIV> <DIV>This is the last DIV.</DIV> </BODY> </HTML> 

click to view at full size.

Figure 14-4. The CSS attributes page-break-before and page-break-after affect the appearance of the printout, not the displayed page.

This listing results in a five-page printout. The first page contains only the first DIV. The second DIV has its page-break-before CSS attribute set to always, so a page break is inserted before the DIV and it appears on the second page. The third DIV also appears on the second page. It has page-break-after set to always, so the page breaks after this element. Setting values of left and right causes page breaks in Internet Explorer 4. Internet Explorer 5 should insert one or two page breaks until either a left or right page, as appropriate.

NOTE
Some late betas of Internet Explorer 5 do not support the values left and right. Netscape Navigator 4 does not support the page-break attributes.



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net