如何使堆叠顺序底部的堆叠上下文中包含的元素出现在堆叠顺序较高的不同堆叠上下文中的另一个元素的前面?
e.g:
HTML:
<div class="Parent-1"></div>
<div class="Parent-2">
<div class="pepe"></div>
<div class="pepin"></div>
</div>
CSS:
.Parent-1{
position: absolute;
z-index: 10;
background-color: green;
}
.Parent-2 {
position: absolute;
z-index: 5;
background-color: red;
}
.pepe, .pepin{
background-color: blue;
}
.pepin{
position: fixed;
z-index: 100;
}
this is what i have (this is what it's suppose to happen):
![enter image description here](https://i.stack.imgur.com/ARVZH.jpg)
this is what i want:
![enter image description here](https://i.stack.imgur.com/yk1ai.jpg)
请记住,我无法更改 HTML 中排序的元素,也无法删除 Parent 元素中的 z-index
简短的回答是你不能。这张图片来自MDN 关于堆叠上下文的解释解释得很好:
![enter image description here](https://i.stack.imgur.com/KWZy7.png)
有人讨论过使用转义堆栈上下文position: fixed
但似乎这还没有发生(参见这个fiddle和question产生它的)。
替代解决方案:
对于您来说,一个可能的替代解决方案是嵌套Parent-1
inside Parent-2
然后使用position: absolute
to put Parent-1
无论你想要它在哪里。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)