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

使用Intersection Observer时文本与Header重叠问题求助

解决方案

问题根源是元素堆叠层级冲突:当 header 切换为 fixed 定位后,未设置足够高的 z-index,导致快速滚动时 section 内容会覆盖 header。

只需给 header 相关容器添加 z-index 属性,确保它始终处于最上层:

修改 CSS 中的 .navbar 和 .sticky 类:

.navbar {
  position:absolute;
  left:0;
  right:0;
  top:0;
  z-index: 999; /* 添加此行 */
}
.sticky {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 999; /* 添加此行 */
}

原理:z-index 控制元素在堆叠上下文中的层级,数值越大越靠上。设置为 999 可以确保 header 不会被其他内容覆盖(常规内容不会使用这么高的层级值)。


内容的提问来源于stack exchange,提问作者Marcii

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 08:10:23