You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 11:15:29