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

移动端菜单背景异常求助:菜单无法遮挡后方元素

移动端菜单背景无法遮挡后方元素的解决方案

你的#headerPop菜单已设置白色背景,但仍能看到后方元素,核心原因是缺少z-index属性导致层级不足。fixed定位元素默认层级为auto,当页面中存在其他定位元素(如#body使用relative定位)时,菜单会被下方内容覆盖,从而出现穿透效果。

修复步骤

给#headerPop添加z-index属性,设置一个足够大的值,确保它的层级高于页面其他内容:

#headerPop {
  position: fixed;
  top: 10%;
  left: 0;
  height: 27%;
  width: 100%;
  text-align: center;
  background-color: white;
  visibility: hidden;
  z-index: 100; /* 新增这一行 */
}

同时,为了保证顶部导航栏(#header)始终在菜单上方,可以给它也添加z-index:

#header {
  position: fixed;
  left: 0;
  top: 0;
  height: 10vh;
  width: 100%;
  background-color: rgba(72, 188, 132, 0.425);
  z-index: 101; /* 新增这一行 */
}

验证效果

修改后,点击汉堡按钮打开菜单,白色背景会完全遮挡后方的#body内容,不会再出现元素穿透的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 08:30:13