【发布时间】:2018-07-25 22:13:27
【问题描述】:
目前我正在使用以下 html + css 来获取我的粘性表头:
<html>
<body>
<table class="table table-striped" style="display: block;">
<thead style="position: sticky;top:6.833rem;; background-color: #e5e5e5;z-index: 10;">
<tr>
<th>Heading 1</th>
<th>Long Heading </th>
<th>Heading 2</th>
<th>Very Very Very Very Long Heading</th>
<th>Very Long Heading</th>
</tr>
</thead>
<tbody style="table-layout: fixed;">
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</tbody>
</table>
</body>
</html>
这在 Firefox 中运行良好。但是当我在 Chrome 中运行相同的代码时,thead 不再具有粘性。
如果我添加
display: block;
到它工作的样式,但是我的标题和我的内容列的宽度不再相同了。
有什么建议吗?
【问题讨论】:
标签: css html-table sticky