打印CSS和分页符

时间:2011-01-13 16:55:26

标签: css printing

我想在用户打印网页时插入分页符。

IE 7,Mozilla 3.0,任何Chrome

3 个答案:

答案 0 :(得分:8)

您可以在打印介质样式表中使用CSS page-break-beforepage-break-after属性来实现此目的。

例如:

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

答案 1 :(得分:0)

我只需要这样做一次,但这在IE7 / IE8中运行得很好。但不确定Chrome或Firefox。

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

答案 2 :(得分:0)

尽管大多数Internet用户都喜欢在线阅读网页,但您的某些用户可能希望先打印文章文字然后阅读。

使用CSS,您可以控制断页的位置并在打印时转到下一页。只需将以下CSS代码添加到样式中,然后将分页符类分配给要在下一页上打印的每个标签即可。


a = 8;
b = { some: 'say'};
c = 'life';
d = true;

let o = {
    'a': [a, b, c, d],
    'a1': [],
    'a2': []
}
nSwitchBefore = 2;

o.a.forEach(function(item, i) {
   i < nSwitchBefore ? this.a1.push(item) : this.a2.push(item) ;
}.bind(o));

console.log(o);