开发者

Printing CSS and Page Breaks

开发者 https://www.devze.com 2023-02-04 09:48 出处:网络
I want to insert a page break when users p开发者_如何学Crint my web page. IE 7, Mozilla 3.0 , any ChromeYou can use the CSS page-break-before or page-break-after properties in a print media style she

I want to insert a page break when users p开发者_如何学Crint my web page.

IE 7, Mozilla 3.0 , any Chrome


You can use the CSS page-break-before or page-break-after properties in a print media style sheet to achieve this.

For example:

<style>
    @media print {
        table {
            page-break-after: always;
        }
    }
</style>


I have only had to do this once, but this worked just fine in IE7/IE8. Not sure about Chrome or Firefox though.

<div>This is before the page break.</div>
<div style="page-break-after:always;"></div>
<div>This is after the page break.</div>


Although most Internet users prefer to read web pages online, some of your users might want to print the article text and then read it.

With CSS, you can control the location of broken pages and go to the next page when printing. Just add the following CSS code to your styles, and then assign the page-break class to each tag you want to print on the next page.

page-break {
  page-break-before: always;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消