【发布时间】:2013-11-02 18:18:33
【问题描述】:
我想固定我的表格的标题。表格存在于可滚动的 div 中。请在此处查看我的代码:http://jsfiddle.net/w7Mm8/114/ 请建议我解决此问题。
谢谢
我的代码:
<div style="position: absolute; height: 200px; overflow: auto; ">
<div style="height: 250px;">
<table border="1">
<th>head1</th>
<th>head2</th>
<th>head3</th>
<th>head4</th>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 2</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 1, cell 2</td>
<td>row 1, cell 2</td>
</tr>
</table>
</div>
</div>
【问题讨论】:
-
现代的方法是使用粘性标题,例如
thead {position: -webkit-sticky; position: sticky; top: 0px; z-index: 100;} -
@MikePoole
webkit-sticky做什么? -
@tommy.carstensen
webkit-sticky与 Safari 中的sticky相同。
标签: html css html-table