打印 HTML 表格时,您可以使用 CSS 强制表格的标题行在分页符后再次显示。这种风格:
@media print {
thead { display: table-header-group; }
}
结果:
Caption ------------- Col1 | Col2 ------------- Data1 | Data2 Data3 | Data4 --Page Break-- Col1 | Col2 ------------- Data5 | Data6
有没有办法在分页符后重复表格标题?我认为你可以做类似的事情 caption { display: table-caption-group; }
,但这不存在。该解决方案需要在 IE9 中运行。
最佳答案
恐怕没有办法实现这一点。原则上可以设置 caption { display: table-caption-group; }
,但是由specs ,“如果表格包含多个具有 'display: table-header-group' 的元素,则只有第一个元素会呈现为标题;其他的则被视为具有“display: table-row-group”。”因此,您无法使 thead
和 caption
都重复。此外,IE 9 甚至不允许您单独重复caption
(Firefox 可以)。
解决方法是将 caption
元素转换为作为 thead
元素一部分的表格行。例如,对于两列表:
<table>
<thead>
<tr><th colspan=2>Caption
<tr><th>Header cell <th>Another header cell
</thead>
关于html - 分页后重复表格标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12519135/