HTML页面粘性表头滚动时被表格行数据覆盖问题求助
解决粘性表头被数据行覆盖的问题
问题核心:粘性表头未设置堆叠层级(z-index),滚动时数据行的层级高于表头,导致内容穿透覆盖;若表头无背景色,下方内容也会透过表头显示。
修复后的CSS代码:
.table > :not(:first-child){ border-top: 0; } thead th { position: sticky; top: 0; /* 提升表头层级,确保始终在数据行上方 */ z-index: 10; /* 设置背景色,避免下方内容透过表头显示,可根据页面样式调整颜色 */ background-color: #fff; } thead th:after { content:''; position: absolute; left: 0; bottom: 0; width: 100%; border-bottom: 2px solid white; }
- 额外注意:如果表格父元素设置了
overflow: hidden/auto/scroll,需确认该容器是你特意用来实现表格内滚动的容器,否则会破坏粘性定位的生效条件。
内容的提问来源于stack exchange,提问作者whyError
相关产品推荐
相关产品推荐

