gpt4 book ai didi

html - Z-Index 不适用于位置为 :relative when its parent is position:absolute 的元素

转载 作者:行者123 更新时间:2023-11-28 12:48:42 24 4
gpt4 key购买 nike

我正在尝试构建一个页面教程之类的东西,其中 div 在页面上突出显示。我有一个模态对话框,通常显示在叠加层之上。但是,我想要做的是将模态对话框放在叠加层后面,但将该模态中的特定 div 放在前面。

Here is a JS fiddle of my code .

如何让 div 显示在叠加层之上?

CSS:

    .overlay 
{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
z-index:1000;
background-color:#000000;
opacity:0.7;
}

.modal
{
position:absolute;
top:300px;
left:50%;
z-index:999;
overflow:auto;
margin:-250px 0px 0px -280px;
border:1px solid #999;
background-color:#fff;
border-radius:6px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);
-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);
box-shadow:0 3px 7px rgba(0,0,0,0.3);
background-clip:padding-box;
padding:10px;
}

.highlight
{
z-index:1002;
position:relative;
background-color:#ffffff;
}

.modal-contents
{
height:100px;
min-width:100px;
}



.section
{
padding:5px;
}

html:

<body>
<div class="overlay"></div>
<div class="modal">
<h1>Modal Window</h1>
<div class="modal-contents">
<div class="section highlight">
This div should be highlighted above the overlay!
</div>
<div class="section">
This is section two
</div>
</div>
</div>
</body>

最佳答案

删除模态元素的所有 z-index 值和白色背景 http://jsfiddle.net/TfSa5/

 .overlay 
{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;

background-color:#000000;
opacity:0.7;
}

.modal
{
position:absolute;
top:300px;
left:50%;

overflow:auto;
margin:-250px 0px 0px -280px;
border:1px solid #999;
border-radius:6px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);
-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);
box-shadow:0 3px 7px rgba(0,0,0,0.3);
background-clip:padding-box;
padding:10px;
}

.modal-contents
{
height:100px;
min-width:100px;
}

.highlight
{
position:relative;
background-color:#ffffff;
}

.section
{
padding:5px;
}

关于html - Z-Index 不适用于位置为 :relative when its parent is position:absolute 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165186/

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