樣式:
<style media="print">
.Noprint { DISPLAY: none;}
.PageNext { PAGE-BREAK-AFTER: always }
</style>
注:
①、不需要打印的對象要用上“Noprint”樣式。
②、需要換頁處理的對象要用上“PageNext”樣式。
③、因為最后一頁不用加入換頁符,所以要控制最后一頁不要使用該樣式。個人感覺用PAGE-BREAK-BEFORE屬性控制第一頁要方便一些。
=====================================================================================
page-break-before和page-break-after(來自網絡)
page-break-before和page-break-after CSS屬性並不會修改網頁在屏幕上的顯示,這兩個屬性是用來控制文件的打印方式。每個打印屬性都可以設定4種設定值:auto、always、left和right。
Auto:是默認值,只有在有需要時,才需設定分頁符號 (Page breaks)。
page-break-before若設定成always:則是在遇到特定的組件時,打印機會重新開始一個新的打印頁。
page-break-before若設定成left:則會插入分頁符號,直到指定的組件出現在一個左邊的空白頁上。
page-break-before若設定成right:則會插入分頁符號,直到指定的組件出現在一個右邊的空白頁上。
page-break-after屬性會將分頁符號加在指定組件后,而非之前。
設置為left或right 與 設置為alvays究竟有什么區別,上面紅色字體的說明看不明白,希望看到貼字的明白人指點一二。
不過用“always”值再加以控制一般的問題都能解決,以下為例子:
<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-before: always"> This is the third DIV.</div> <div style="page-break-before: always"> This is the fourth DIV.</div> </body> </html>
或
<html> <head> <title>Listing 14-4</title> </head> <body> <div style="page-break-after: always"> This is the first DIV.</div> <div style="page-break-after: 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> </body> </html>
程序員的基礎教程:菜鳥程序員