效果图如上,
因为项目经理希望竖向滚动条永远在最外面,所以通过粘性布局实现表头固定;
由于列数过多,固定多选框列和操作列时发现出现了滚动条,看官网上的例子也有,通过检查元素发现是固定列的阴影(使用伪元素实现)导致的高度超出。
固定表头样式
由于我希望表头是相对整个页面,也就是body元素进行定位,所以需要将表头元素与body之间的元素的 overflow 属性移除掉。
关于粘性布局的知识大家可以上mdn查看:mdn css position
.el-table {
/* 取消overflow 设置, 为table header 粘性布局 */
overflow: unset !important;
}
/* header粘性布局 */
.el-table__header-wrapper {
position: sticky;
top: 220px;/* 按照自己的需求设置 */
z-index: 3;
}
固定列导致的竖向滚动
已知出现竖向滚动是由于固定列的伪元素导致的,所以只需要调整伪元素即可。
.el-table__body-wrapper tr td.el-table-fixed-column--left.is-first-column::before,
.el-table__body-wrapper tr td.el-table-fixed-column--left.is-last-column::before,
.el-table__body-wrapper tr td.el-table-fixed-column--right.is-first-column::before,
.el-table__body-wrapper tr td.el-table-fixed-column--right.is-last-column::before,
.el-table__body-wrapper tr th.el-table-fixed-column--left.is-first-column::before,
.el-table__body-wrapper tr th.el-table-fixed-column--left.is-last-column::before,
.el-table__body-wrapper tr th.el-table-fixed-column--right.is-first-column::before,
.el-table__body-wrapper tr th.el-table-fixed-column--right.is-last-column::before,
.el-table__footer-wrapper tr td.el-table-fixed-column--left.is-first-column::before,
.el-table__footer-wrapper tr td.el-table-fixed-column--left.is-last-column::before,
.el-table__footer-wrapper tr td.el-table-fixed-column--right.is-first-column::before,
.el-table__footer-wrapper tr td.el-table-fixed-column--right.is-last-column::before,
.el-table__footer-wrapper tr th.el-table-fixed-column--left.is-first-column::before,
.el-table__footer-wrapper tr th.el-table-fixed-column--left.is-last-column::before,
.el-table__footer-wrapper tr th.el-table-fixed-column--right.is-first-column::before,
.el-table__footer-wrapper tr th.el-table-fixed-column--right.is-last-column::before,
.el-table__header-wrapper tr td.el-table-fixed-column--left.is-first-column::before,
.el-table__header-wrapper tr td.el-table-fixed-column--left.is-last-column::before,
.el-table__header-wrapper tr td.el-table-fixed-column--right.is-first-column::before,
.el-table__header-wrapper tr td.el-table-fixed-column--right.is-last-column::before,
.el-table__header-wrapper tr th.el-table-fixed-column--left.is-first-column::before,
.el-table__header-wrapper tr th.el-table-fixed-column--left.is-last-column::before,
.el-table__header-wrapper tr th.el-table-fixed-column--right.is-first-column::before,
.el-table__header-wrapper tr th.el-table-fixed-column--right.is-last-column::before {
bottom: 0px !important;
}