【发布时间】:2019-09-04 17:38:45
【问题描述】:
我想要两张并排的桌子......
- 共享同一个垂直滚动
- 有单独的水平卷轴
- 有粘性标题
...都在一个灵活的宽度和高度的容器内。
这是我尝试的代码笔:https://codepen.io/numberjak/pen/gOYGEKz
如您所见,我已经勾选了我的所有要求,除了两个表都有粘性标题。
<div class="container">
<div class="scroll red">
<table>
<thead>
<tr>
<th>Scroll 1</th>
<th>Scroll 2</th>
<th>Scroll 3</th>
<th>Scroll 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
</div>
<div class="scroll blue">
<table>
<thead>
<tr>
<th>Scroll 1</th>
<th>Scroll 2</th>
<th>Scroll 3</th>
<th>Scroll 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
</div>
</div>
html {
height: 100%;
background-color: black;
}
div {
display: flex;
}
.container {
overflow: auto;
align-items: flex-start;
max-height: 20rem;
}
thead th {
position: sticky;
top: 0;
background-color: grey;
}
td, th {
min-width: 30rem;
padding: 1rem;
background-color: white;
}
tr {
height: 10rem;
}
.scroll {
overflow: auto;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
【问题讨论】:
-
这打破了共享的垂直滚动行为
-
更新了钢笔codepen.io/gc-nomade/pen/qBWVraP,你会得到两个容器的滚动条,它们都有滚动类,所以这似乎是你所期望的;)只从
.container中删除了align-items: flex-start;
标签: javascript html css