gpt4 book ai didi

javascript - 修复可滚动 div 顶部的表头

转载 作者:太空宇宙 更新时间:2023-11-04 11:39:49 25 4
gpt4 key购买 nike

本例中的div是可滚动的,如何让表格的header固定在div的顶部?

<div id="table" style="overflow: auto; border: 1px solid;">
<table id="table_id">
<tr>
<th>A</th>
<th>B</th>
</tr>

<tr>
<td>A</td>
<td>B</td>
</tr>

</table>
</div>

最佳答案

我会分成 2 个部分并指定宽度(如果响应则为 %)。

<table id="table-top">
<tr>
<th>A</th>
<th>B</th>
</tr>
</table>
<div id="table">
<table id="table_id">
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
</tr>
</table>
</div>

CSS ....

#table{
overflow-y: auto;
height:150px;
border-bottom:1px solid grey;
}
table{
width:100%;
}
table td, table th{
border-color: grey;
border: 1px solid;
width:50%;
}

https://jsfiddle.net/tonytansley/mvp4u54q/

关于javascript - 修复可滚动 div 顶部的表头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31433833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com