我需要一个简单的解决方案。我知道这与其他一些问题类似,例如:
但我只需要冻结一个左列,我更喜欢一个简单且无脚本的解决方案。
原文由 agsamek 发布,翻译遵循 CC BY-SA 4.0 许可协议
我需要一个简单的解决方案。我知道这与其他一些问题类似,例如:
但我只需要冻结一个左列,我更喜欢一个简单且无脚本的解决方案。
原文由 agsamek 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用 sticky
位置。这是一个示例代码。这是 HTML/CSS 解决方案。不需要js。
.view {
margin: auto;
width: 600px;
}
.wrapper {
position: relative;
overflow: auto;
border: 1px solid black;
white-space: nowrap;
}
.sticky-col {
position: -webkit-sticky;
position: sticky;
background-color: white;
}
.first-col {
width: 100px;
min-width: 100px;
max-width: 100px;
left: 0px;
}
.second-col {
width: 150px;
min-width: 150px;
max-width: 150px;
left: 100px;
}
<div class="view">
<div class="wrapper">
<table class="table">
<thead>
<tr>
<th class="sticky-col first-col">Number</th>
<th class="sticky-col second-col">First Name</th>
<th>Last Name</th>
<th>Employer</th>
</tr>
</thead>
<tbody>
<tr>
<td class="sticky-col first-col">1</td>
<td class="sticky-col second-col">Mark</td>
<td>Ham</td>
<td>Micro</td>
</tr>
<tr>
<td class="sticky-col first-col">2</td>
<td class="sticky-col second-col">Jacob</td>
<td>Smith</td>
<td>Adob Adob Adob AdobAdob Adob Adob Adob Adob</td>
</tr>
<tr>
<td class="sticky-col first-col">3</td>
<td class="sticky-col second-col">Larry</td>
<td>Wen</td>
<td>Goog Goog Goog GoogGoog Goog Goog Goog Goog Goog</td>
</tr>
</tbody>
</table>
</div>
</div>
codeply代码: https ://www.codeply.com/p/oZ4NjpvwbO
原文由 Circuit Breaker 发布,翻译遵循 CC BY-SA 4.0 许可协议
3 回答920 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
2 回答929 阅读✓ 已解决
2 回答1.5k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
2 回答902 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
如果您想要一个只有列水平滚动的表格,您可以
position: absolute
第一列(并明确指定其宽度),然后将整个表格包装在overflow-x: scroll
块中。不要费心在 IE7 中尝试这个,但是……相关的 HTML 和 CSS:
小提琴