分页符后重复表格标题 [英] Repeating table caption after page break

查看:184
本文介绍了分页符后重复表格标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印HTML表格时,可以使用CSS强制在分页符后再次显示表格的标题行。这种风格:

When printing an HTML table, you can use CSS to force the table's header row to display again after the page break. This style:

@media print {
   thead { display: table-header-group; }
}

结果为:

Results in:


Caption
-------------
Col1  | Col2
-------------
Data1 | Data2
Data3 | Data4

--Page Break--

Col1  | Col2
-------------
Data5 | Data6

有没有办法在分页符后重复表格标题?我认为你可以做一些像 caption {display:table-caption-group; } ,但这不存在。解决方案将需要在IE9中工作。

Is there a way to also repeat the table caption after the page break? I would think you could do something like caption { display: table-caption-group; }, but this doesn't exist. The solution would need to work in IE9.

推荐答案

恐怕没有办法做到这一点。原则上,您可以设置 caption {display:table-caption-group; } ,但通过规范 ,如果一个表包含具有'display:table-header-group'的多个元素,则只有第一个元素被渲染为标题;其他人被视为他们有'display:table-row-group'。所以你不能同时使 thead 标题重复。此外,IE 9甚至没有让你单独重复 caption (Firefox)。

I’m afraid there is no way to achieve that. In principle, you can set caption { display: table-caption-group; }, but by the specs, "If a table contains multiple elements with 'display: table-header-group', only the first is rendered as a header; the others are treated as if they had 'display: table-row-group'." So you would not be able to make both the thead and the caption repeat. Besides, IE 9 does not get even let you repeat caption alone (Firefox does).

解决方法是将标题元素转换为属于 thead 元素一部分的表格行。例如,对于两列表:

The workaround is to turn the caption element to a table row that is part of the thead element. E.g., for a two-column table:

<table>
<thead>
<tr><th colspan=2>Caption
<tr><th>Header cell <th>Another header cell
</thead>

这篇关于分页符后重复表格标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆