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

导航栏展开时关闭图标(X)不显示的问题排查求助

解决方案

两个核心问题导致了关闭图标不显示:

  1. CSS选择器错误
    你写的.img.menu.hide是错误的——这个选择器是找同时带有img、menu、hide三个类的元素,但你的菜单图标是<img class="menu">,正确的选择器应该是img.menu.hide(元素选择器+类选择器)。这个错误导致点击后菜单图标没被隐藏,直接覆盖在关闭图标上方,所以看不到关闭按钮。

  2. 导航栏层级覆盖图标
    展开后的导航栏是position: absolute且占满全屏,它的层级默认和未定位的toggle-box一致,会把图标盖住。给toggle-box添加相对定位和更高的z-index,就能确保图标始终在导航栏之上。

修改后的完整CSS:

section {
  background-color: blue;
  padding: 20px;
  /* height: 40px; */
  display: flex;
  justify-content: space-between;
  align-items: center;
}

img {
  height: 30px;
  width: auto;
}

/* 新增:让toggle-box层级高于导航栏 */
.toggle-box {
  position: relative;
  z-index: 999;
}

.toggle-box a img {
  filter: invert(1);
}

/* 修正选择器 */
img.menu.hide {
  display: none;
}

img.close {
  display: none;
}

/* 把flex改成block,更适合图片元素 */
img.close.show {
  display: block;
}

nav.navigation {
  display: none;
}

nav.navigation.active {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: blue;
}

nav.navigation.active a {
  padding: 20px;
  color: #ffffff;
  font-size: 20px;
  font-weight: bold;
  text-decoration: none;
}

.phone-logo a img {
  filter: invert(1);
}

另外,把img.close.show的display:flex换成display:block更合理,图片本身是行内块元素,用block布局不会有额外的flex属性干扰。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 06:24:04