我正在尝试制作一个带有一些相当长的表格的可打印文档。有时页面正好在表头和数据之间结束,这使得阅读变得更加困难。
我怎样才能防止这种情况发生呢?
我尝试使用以下 CSS,但没有帮助。
@media print {
h1, h2, h3, thead, thead>tr {
page-break-after: avoid;
page-break-inside: avoid;
}
tbody {
page-break-before: avoid;
}
/* I would also like to not have page breaks within first five rows */
tbody:nth-child(-n+5) {
page-break-before: avoid;
}
}
Run Code Online (Sandbox Code Playgroud)
表结构:
<table border="1" cellspacing="0" cellpadding="3">
<thead>
<tr>
<th rowspan="2">Metric</th>
<th colspan="3">Type 1</th>
<th colspan="3">Type 2<th>
</tr>
<tr>
<th>Initial</th>
<th>Final</th>
<th>Difference</th>
<th>Initial</th>
<th>Final</th>
<th>Difference</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dataset1</td>
<td>*DATA*</td>
...
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)