html - 分页后重复表格标题

标签 html css printing css-tables caption

打印 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”。”因此,您无法使 theadcaption 都重复。此外,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/

相关文章:

javascript - JS 在 Canvas 上绘制图像

html - Firefox 和 IE 中字体系列 css 属性的问题

java - 打印字符串数组也打印 null

shell - 在awk中,如何在打印$2时忽略错误行,但错误行中不存在$2

windows - 我想创建一个批处理脚本,它将按修改日期的顺序打印文件夹中的所有文件

html - 用一些像素从左右插入边框底部

javascript - 我想为 appendChild() 设置动画,使其淡入

html - 为什么 vertical-align 会偏移这个 inline-level 框?

html - 页面在大多数浏览器中显示正确,但在 Safari 中不正确

html - 创建一个适合页面的 div 和一个均匀填充在里面的 child