几个绝对定位元素的 z-index 问题
是否可以将位于绝对定位元素内部并位于另一个绝对定位元素下方的元素置于前台?
例如:
<div id="el1">
<div id="test1">Test 1</div>
</div>
<div id="el2">
<div id="test2">Test 2</div>
</div>
CSS:
#el1, #el2, #test1, #test2 {
position: absolute;
top: 0;
left: 0;
}
#el1 {
z-index: 2;
}
#el2 {
z-index: 1;
}
#test1, #test2 {
z-index: 3;
}
所有元素都是绝对定位的,第一个元素位于第二个元素之上。现在我想将两个测试元素放在前台。这是不可能的,因为第二个 z-index 不适用,因为它位于 #el2 内部。有没有解决方案,或者我是否必须将测试元素放在其他元素之外?
Is it possible to bring an element into foreground that is inside an absolute positioned element and lying under another absolute positioned element?
For example:
<div id="el1">
<div id="test1">Test 1</div>
</div>
<div id="el2">
<div id="test2">Test 2</div>
</div>
CSS:
#el1, #el2, #test1, #test2 {
position: absolute;
top: 0;
left: 0;
}
#el1 {
z-index: 2;
}
#el2 {
z-index: 1;
}
#test1, #test2 {
z-index: 3;
}
All elements are absolute positioned and the first is lying over the second. Now I want to have both test-elements in the foreground. That's not possible because for the second the z-index does not apply because it's inside #el2. Is there any solution for this or do I have to put the test-elements outside the others?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子元素将继承父元素的
z-index
。您必须更改标记的结构以反映所需的 z 索引。The child elements will inherit the parents'
z-index
. You will have to change the structure of your markup to refelect the desired z-indexing.