简体   繁体   English

Chrome 浏览器 - 打印标题中包含多行的表格问题

[英]Chrome browser - printing tables with multiple rows in headers issue

The goal - to print pages with tables the following way:目标- 通过以下方式打印带有表格的页面:

  1. If the whole table is taller than A4 paper list, to duplicate headers for each page如果整个表格高于 A4 纸列表,则为每一页复制标题
  2. If the table is smaller than A4 paper list, to not break the page before next table如果表格小于 A4 纸列表,不在下一个表格之前分页

For one-row headers, this CSS property works as it should:对于单行标题,此 CSS 属性按应有的方式工作:

page-break-inside:auto;

The problem - it comes by using more complicated table headers with 2+ rows, when such headers are somewhere at the middle of page break.问题- 它来自于使用具有 2+ 行的更复杂的表头,当这些表头位于分页符中间的某个位置时。

For better reference, here is the sample table code which can be used.为了更好地参考,这里是可以使用的示例表代码。 Please be sure to open HTML file with this code only, without any additional code usually provided by build-in code snippet tool:请务必仅使用此代码打开 HTML 文件,不要使用内置代码片段工具通常提供的任何其他代码:

 <style> td { border: 1px solid lightblue; padding: 10px; } table { page-break-inside: auto; } tbody td { border: 1px solid blue; font-weight: bold; } </style> <table> <thead> <tr> <td> <div>this is table header 1</div> </td> </tr> <tr> <td> <div>this is table header 2</div> </td> </tr> <tr> <td> <div>this is table header 3</div> </td> </tr> </thead> <tbody> <tr> <td> <div>this is table body 1</div> </td> </tr> <tr> <td> <div>this is table body 2</div> </td> </tr> <tr> <td> <div>this is table body 3</div> </td> </tr> <tr> <td> <div>this is table body 4</div> </td> </tr> <tr> <td> <div>this is table body 5</div> </td> </tr> <tr> <td> <div>this is table body 6</div> </td> </tr> <tr> <td> <div>this is table body 7</div> </td> </tr> <tr> <td> <div>this is table body 8</div> </td> </tr> <tr> <td> <div>this is table body 9</div> </td> </tr> <tr> <td> <div>this is table body 10</div> </td> </tr> <tr> <td> <div>this is table body 11</div> </td> </tr> <tr> <td> <div>this is table body 12</div> </td> </tr> <tr> <td> <div>this is table body 13</div> </td> </tr> <tr> <td> <div>this is table body 14</div> </td> </tr> <tr> <td> <div>this is table body 15</div> </td> </tr> <tr> <td> <div>this is table body 16</div> </td> </tr> <tr> <td> <div>this is table body 17</div> </td> </tr> <tr> <td> <div>this is table body 18</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> </tbody> </table> <table> <thead> <tr> <td> <div>this is table header 1</div> </td> </tr> <tr> <td> <div>this is table header 2</div> </td> </tr> <tr> <td> <div>this is table header 3</div> </td> </tr> </thead> <tbody> <tr> <td> <div>this is table body 1</div> </td> </tr> <tr> <td> <div>this is table body 2</div> </td> </tr> </tbody> </table>

If you try to print the following HTML page, this issue appears: screenshot of the issue如果您尝试打印以下 HTML 页,则会出现此问题:问题的屏幕截图

What was tried尝试了什么

different combinations of all page-break related properties for table header tags.表 header 标签的所有分页相关属性的不同组合。

 td { border: 1px solid lightblue; padding: 10px; } tbody td { border: 1px solid blue; font-weight: bold; }.avoid-page-break { page-break-inside: avoid; break-inside: avoid; position: relative; }
 <div class="avoid-page-break"> <table> <thead> <tr> <td> <div>HEAD OF TABLE 1</div> </td> </tr> <tr> <td> <div>HEAD OF TABLE 1</div> </td> </tr> <tr> <td> <div>HEAD OF TABLE 1</div> </td> </tr> </thead> <tbody> <tr> <td> <div>this is table body 1</div> </td> </tr> <tr> <td> <div>this is table body 2</div> </td> </tr> <tr> <td> <div>this is table body 3</div> </td> </tr> <tr> <td> <div>this is table body 4</div> </td> </tr> <tr> <td> <div>this is table body 5</div> </td> </tr> <tr> <td> <div>this is table body 6</div> </td> </tr> <tr> <td> <div>this is table body 7</div> </td> </tr> <tr> <td> <div>this is table body 8</div> </td> </tr> <tr> <td> <div>this is table body 9</div> </td> </tr> <tr> <td> <div>this is table body 10</div> </td> </tr> <tr> <td> <div>this is table body 11</div> </td> </tr> <tr> <td> <div>this is table body 12</div> </td> </tr> <tr> <td> <div>this is table body 13</div> </td> </tr> <tr> <td> <div>this is table body 14</div> </td> </tr> <tr> <td> <div>this is table body 15</div> </td> </tr> <tr> <td> <div>this is table body 16</div> </td> </tr> <tr> <td> <div>this is table body 17</div> </td> </tr> <tr> <td> <div>this is table body 18</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> <tr> <td> <div>this is table body 19</div> </td> </tr> </tbody> </table> </div> <div class="avoid-page-break"> <table> <thead> <tr> <td> <div>HEAD OF TABLE 2</div> </td> </tr> <tr> <td> <div>HEAD OF TABLE 2</div> </td> </tr> <tr> <td> <div>HEAD OF TABLE 2</div> </td> </tr> </thead> <tbody> <tr> <td> <div>this is table body 1</div> </td> </tr> <tr> <td> <div>this is table body 2</div> </td> </tr> </tbody> </table> </div>

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

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