介绍一种用css实现表格表头固定,横向纵向可滑动的方法
先用一个div把表格包起来,表格给定高宽,overflow:scroll。
然后给表头写一个黏性布局 position: sticky;top:0。就轻松实现了。
<div class="scroll-box">
<table class="tableFixHead">
<thead>
</thead>
<tbody></tbody>
</table>
</div>
.scroll-box {
width: 100%;
max-height: 500px;
overflow: scroll;
}
.tableFixHead thead {
position: sticky;
top: 0;
}