html - 菜单栏与内容重叠
问题描述
当我以移动屏幕大小打开菜单栏时,它会与内容重叠,但这仅发生在主页上的产品页面上,它不会与内容重叠产品卡上没有 Z 索引
这是菜单栏的CSS
CSS代码
@media (max-width: 768px) {
#menu-bar {
display: initial;
z-index: 9999;
}
#menu-bar {
font-size: 2rem;
border-radius: 0.5rem;
border: 0.1rem solid var(--black);
padding: 0.8rem 1.5rem;
color: var(--black);
cursor: pointer;
display: none;
}
javascript代码:
let menu = document.querySelector('#menu-bar');
let navbar = document.querySelector('.navbar');
let header = document.querySelector('.header-2');
menu.addEventListener('click', () => {
menu.classList.toggle('fa-times');
navbar.classList.toggle('active');
});
window.onscroll = () => {
menu.classList.remove('fa-times');
navbar.classList.remove('active');
if (window.scrollY > 150) {
header.classList.add('active');
} else {
header.classList.remove('active');
}
}
HTML 代码:
<div class="header-2">
<div id="menu-bar" class="fas fa-bars"></div>
<nav class="navbar">
<a href="index.html">home</a>
<a href="#product">products</a>
<a href="#category">Category</a>
<a href="about.html">about</a>
<a href="#contact">contact</a>
</nav>
<div class="icons">
<a href="login.html">Login</a>
<a href="#" class="fas fa-user-circle"></a>
</div>
</div>
解决方案
您没有提供足够的代码,所以我只能猜测。这绝对是一个 z-index 问题,可能的原因是:
- 您的产品卡片(它们的子项)的 z-index >=9999,这意味着它仅比菜单 z-index 大。
- 您的菜单位于 parent 中,其 z-index 比菜单本身的小。在这种情况下,你有一个堆叠上下文问题,所以你的菜单 z-index 实际上不是 9999(所以它比卡片 z-index 小)
推荐阅读
- python - 如何在 Python 散点图中使字体大小更小?
- c++ - gcc的“__builtin_popcount”如何工作?
- python - matplotlib 交互式绘图不绘制
- sql - 从不相关的表中一次插入两个或多个值
- react-native - React Native NativeModule.ImagePickermanager 为空
- python - 我应该如何正确使用 unittest.mock.patch 在单元测试中使用假对象?
- r - 闪亮的 RQDA 查询
- mysql - MYSQL JSON - 在其兄弟键值上使用 WHERE 提取部分 JSON 字段
- jmeter - Jmeter请求不断给出403邮递员工作和浏览器工作的地方
- python - 使用 Scrapy 提取数据并遇到 css.seletor 问题