简体   繁体   English

page-before-before:避免; 为什么还存在分页符?

[英]page-break-before: avoid; Why is there still a page break?

I have a table element that is often very tall (it has many rows), and when the rendered browser print screen displays, there is always a page break between the header and the beginning of the table. 我有一个通常很高的表格元素(它有很多行),并且在显示呈现的浏览器打印屏幕时,在标题和表格的开头之间总是存在一个分页符。 This remains true upon physically printing the document. 在实际打印文档时仍然如此。

I'd like to remove this page break, as it wastes a lot of space, unnecessarily. 我想删除此分页符,因为它不必要地浪费了很多空间。 I tried using this code: 我尝试使用此代码:

table {
    page-break-before: avoid;
}

... but to no avail. ...但无济于事。 Is this the proper code? 这是正确的代码吗? Or is there something else I should be using? 还是还有其他我应该使用的东西?

Please see the image below and notice the page break (the table is very tall but I only pasted the first five rows or so): 请参见下图,并注意分页符(表很高,但我只粘贴了前五行左右):

在此处输入图片说明

It is difficult from the sample you are sharing for us to know where the pagebreak is being expressed. 从您共享的样本中,我们很难知道分页符在哪里表达。 All your attempt is doing is expressing to avoid pagebreak before the TABLE element. 您所做的所有尝试都是为了避免在TABLE元素之前进行分页。 By the looks of your print sample, it would appear that your pagebreak is occurring either before the TABLE element or before the TH element. 从打印样本的外观来看,您的分页符似乎发生在TABLE元素之前或TH元素之前。 Again, we cant know for sure without seeing all the code. 再次,我们无法完全看到所有代码就无法确定。 There could be some overriding css that expresses greater importance. 可能会有一些更重要的CSS表现出更大的重要性。 There might ALSO be a pagebreak after the element preceding the table. 在表格前面的元素之后可能还会有一个分页符。 Just for kicks, try doing it with the table and tr elements. 只是为了踢,尝试使用table和tr元素。 Also try adding !important. 也可以尝试添加!important。

@media print {
  table {page-break-before: avoid !important;}
  tr {page-break-before: avoid !important;}
}

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

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