简体   繁体   English

CSS中的分页属性应该如何工作?

[英]How are the page-break properties in CSS supposed to work?

Modern browsers are supposed to support the CSS page-break properties to some degree. 现代浏览器应该在某种程度上支持CSS分页符属性 However I haven't been able to get any browser to print any differently when I use avoid , widows , or orphans . 但是,当我使用avoidwidowsorphans时,我无法让任何浏览器以不同的方式进行打印。 Am I doing it wrong, or is the browser support just not as solid as advertised? 我做错了,还是浏览器支持不像宣传的那样稳固?

      h2 {
        page-break-after: avoid;
      }                         

      p {
        page-break-inside: avoid;   
        orphans: 2;
        widows: 2;
      }

Browser support for printing sucks. 浏览器支持打印很糟糕。 Not just a little bit, but completely totally and without compare. 不仅仅是一点点,而是完全没有比较。 About once every other year (for the past 10), I've played around with this and I always come back to the same conclusion: don't depend on the browser to be able to handle good printing. 大约每隔一年(过去10年),我已经玩过这个并且我总是回到相同的结论:不依赖于浏览器能够处理好的打印。

If it absolutely must be positioned correctly, create a pdf file on the fly and let the user print that. 如果绝对必须正确定位,请动态创建一个pdf文件并让用户打印出来。

If you are wanting to do a page break I know that this is the way it works at least in Firefox and IE. 如果你想要分页,我知道这是它至少在Firefox和IE中的工作方式。 Last time I checked this worked in IE7. 上次我检查这个在IE7中工作。

Page 1

<br style="page-break-after:always" />

Page 2

It should print the pages on separate pieces of paper, totally depending on the browser. 应该在不同的纸上打印页面,完全取决于浏览器。

I know this will go against everything everyone says about html development, but use tables . 我知道这会违背每个人对html开发所说的一切,但是使用表格 Put content that needs to stay together into a table, and then the page will not be split in the middle of the table. 将需要保留在一起的内容放入表中,然后页面将不会在表的中间拆分。 If the table is longer than one page, then it will be split somewhere in the middle of the table, but using tables is a good way to keep content together when printing. 如果表格长于一页,那么它将被分割到表格中间的某个位置,但使用表格是在打印时将内容保持在一起的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM