我一直在想办法制作一个具有固定第一列的表(以及具有水平溢出的表的其余部分)我看到了一个有类似问题的帖子。但固定列位似乎没有解决。帮助?
原文由 Alan 发布,翻译遵循 CC BY-SA 4.0 许可协议
我一直在想办法制作一个具有固定第一列的表(以及具有水平溢出的表的其余部分)我看到了一个有类似问题的帖子。但固定列位似乎没有解决。帮助?
原文由 Alan 发布,翻译遵循 CC BY-SA 4.0 许可协议
怎么样:
table {
table-layout: fixed;
width: 100%;
*margin-left: -100px; /*ie7*/
}
td, th {
vertical-align: top;
border-top: 1px solid #ccc;
padding: 10px;
width: 100px;
}
.fix {
position: absolute;
*position: relative; /*ie7*/
margin-left: -100px;
width: 100px;
}
.outer {
position: relative;
}
.inner {
overflow-x: scroll;
overflow-y: visible;
width: 400px;
margin-left: 100px;
}
<div class="outer">
<div class="inner">
<table>
<tr>
<th class=fix></th>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th class="fix">Col 5</th>
</tr>
<tr>
<th class=fix>Header A</th>
<td>col 1 - A</td>
<td>col 2 - A (WITH LONGER CONTENT)</td>
<td>col 3 - A</td>
<td>col 4 - A</td>
<td class=fix>col 5 - A</td>
</tr>
<tr>
<th class=fix>Header B</th>
<td>col 1 - B</td>
<td>col 2 - B</td>
<td>col 3 - B</td>
<td>col 4 - B</td>
<td class=fix>col 5 - B</td>
</tr>
<tr>
<th class=fix>Header C</th>
<td>col 1 - C</td>
<td>col 2 - C</td>
<td>col 3 - C</td>
<td>col 4 - C</td>
<td class=fix>col 5 - C</td>
</tr>
</table>
</div>
</div>
你可以在这个 jsbin 中测试它:http: //jsbin.com/uxecel/4/edit
原文由 skube 发布,翻译遵循 CC BY-SA 3.0 许可协议
2 回答1.5k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
2 回答922 阅读✓ 已解决
1 回答929 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
2 回答799 阅读
1 回答803 阅读✓ 已解决
我有一个类似的表格,样式如下: