我知道这个问题,但没有一个答案适用于Safari,Chrome等.
接受的策略(如此处所示)是设置tbody高度和溢出属性,如下所示:
<table>
<thead>
<tr><th>This is the header and doesn't scroll</th></tr>
</thead>
<tbody style="height:100px; overflow:auto;">
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
<tr><td>content that scrolls</td></tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这在任何webkit浏览器中都不起作用.有一个关于它的错误报告似乎不是一个高优先级(据报道,05年6月).
所以我的问题是:是否有其他策略确实有效?我尝试过双表方法,但是不可能保证标题与内容对齐.我只需要等待Webkit修复它吗?