gpt4 book ai didi

html - z-index 值不适用于元素?

转载 作者:太空宇宙 更新时间:2023-11-04 02:51:56 26 4
gpt4 key购买 nike

我有一个带有汉堡标志的 div,被另一个 div 覆盖。我希望汉堡标志堆叠在所有东西之上。所以我将 z-index 值应用到我认为合适的地方。但是它不起作用。谁能解释为什么?下面是我的代码笔,请看一下。

代码笔:

http://codepen.io/tbeckett24/pen/qORBbE

html:

<body>
<div id="photoCover">
<nav id="menu" class="menu">
<a href="#" class="menu-trigger"><span>Menu</span></a>
</nav>
</div><!--photoCover-->
<div id="entryMenu"></div><!--entryMenu-->
</body>

CSS:

html { 
background: green;
width: 100%;
height:100%;
}
body {
width: 100%;
height:100%;
position: relative;
}
#photoCover {
width:100%;
height:100%;
position: fixed;
top: 0;
left:0;
background-color: rgba(0,0,0,0.6);
}
.menu {
position: fixed;
top: 0; right: 0;
width: 100%;
background-color: rgba(0,0,0,0);
-webkit-backface-visibility: hidden;
}
.menu-trigger {
position: fixed;
top: 2%; right: 2%;
display: block;
width: 60px; height: 60px;
cursor: pointer;
background: red;
z-index:3000;
}
.menu-trigger span {
position: absolute;
top: 50%; left: 0;
display: block;
width: 100%; height: 6px;
margin-top: -2px;
background-color: #fff;
font-size: 0px;
-webkit-touch-callout: none;
user-select: none;
-webkit-transition: background-color 0.3s;
transition: background-color 0.3s;
z-index: 2000;
}
.menu-trigger span:before,
.menu-trigger span:after {
position: absolute;
left: 0;
width: 100%; height: 100%;
background: #fff;
content: '';
}
.menu-trigger span:before {
-webkit-transform: translateY(-270%);
transform: translateY(-270%);
}
.menu-trigger span:after {
-webkit-transform: translateY(270%);
transform: translateY(270%);
}
#entryMenu {
position: fixed;
top:0;
left:0;
height:100%;
width:100%;
background-color: rgba(0,0,0,0.9);
}

最佳答案

通过向 parent-div 添加一个 z-index,我在顶层得到了“汉堡包”。

#photoCover {
(...)
z-index:99;
}

我相信原因是 #photoCover#entryMenu 都是固定的并且在同一个地方,#entryMenu 位于顶部,因为它是最后添加的。

关于html - z-index 值不适用于元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32842526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com