【发布时间】:2020-01-29 11:55:26
【问题描述】:
让我们考虑下图。我正在生成员工工作时间的月度报告。当水平滚动条向右移动时,我希望code,name, area, territory 列固定在其位置,并且日期列应该是水平滚动的。向右滚动时,日期列应位于 code,name, area, territory 列组下方。我该怎么做?有没有可用的 css 技巧或插件?
【问题讨论】:
标签: javascript html css
让我们考虑下图。我正在生成员工工作时间的月度报告。当水平滚动条向右移动时,我希望code,name, area, territory 列固定在其位置,并且日期列应该是水平滚动的。向右滚动时,日期列应位于 code,name, area, territory 列组下方。我该怎么做?有没有可用的 css 技巧或插件?
【问题讨论】:
标签: javascript html css
我认为根据@Circuit Breaker answer 修复列的最简单和合乎逻辑的方法是
.view {
margin: auto;
width: 600px;
}
.wrapper {
position: relative;
overflow: auto;
border: 1px solid black;
white-space: nowrap;
}
.sticky-col {
position: sticky;
position: -webkit-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>
【讨论】: