<分区>
<分区>
为什么 z-index 属性不适用于具有绝对位置的元素,如果此元素的父元素位置固定? 我做的很简单example对于这种情况
HTML:
<div id='q1'>
<div id='q2'></div>
</div>
CSS:
#q1 {
position: fixed;
width: 100%;
height: 50px;
background-color: red;
z-index: 0;
}
#q2 {
position: absolute;
top: 80%;
border: 2px solid black;
width: 100px;
height: 30px;
background-color: green;
z-index: -1;
}
最佳答案
不能那样做,因为 z-index 是相对于同一堆栈的元素的,在您的情况下,您希望子项的 z-index 低于父项的 z-index。
顺便说一下,如果你不让#q2 成为#q1 的 child ,它会像 charm 一样工作。
希望对你有帮助
关于html - 具有固定父级的绝对定位元素上的 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46938250/