如何覆盖“继承” z 索引?
我需要重写继承 z 索引的概念。
例如,在此代码中
<style>
div{
background-color:white;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
</style>
<div style="position: fixed; z-index: 2;">
div 1
<div style="position: fixed; z-index: 3;">
div 2
</div>
</div>
<div style="position: fixed; z-index: 2;">
div 3
</div>
我想要 div 2
显示,但显示的是 div 3
。我怎样才能在不改变我的结构的情况下改变这种行为。
I am needing to override the notion of inherited z-indexes.
For instance in this code
<style>
div{
background-color:white;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
</style>
<div style="position: fixed; z-index: 2;">
div 1
<div style="position: fixed; z-index: 3;">
div 2
</div>
</div>
<div style="position: fixed; z-index: 2;">
div 3
</div>
I want for div 2
to be displayed, but instead div 3
is displayed. How can I change this behavior without changing my structure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能为子级指定比其父级更高的
z-index
。如果是这种情况,您可能需要重新考虑您的设计,或者考虑暂时将子级从父级中弹出,以将其显示在比其父级更高的索引上。在这种情况下,div 的物理顺序也会有所帮助。如果将第一个移到最后一个之后,您将获得首选渲染。但这可能不适合您的情况。
You can't give a child higher
z-index
than its parent. You may want to rethink your design if this is the case, or consider popping the child out of the parent temporarily to show it on a higher index than its parent.The physical order of the divs in this case can help as well. If you move the first down after the last, you'll get the preferred rendering. But this may not be ideal for your situation.