gpt4 book ai didi

html - z-index - 将深层嵌套元素放在最前面

转载 作者:可可西里 更新时间:2023-11-01 14:48:30 27 4
gpt4 key购买 nike

我有下面的 HTML 和 CSS,我想去掉前面的黑色小方 block ,即覆盖层上方和上方,我应该只能看到黑色方 block 。此标记只是我的代码的剥离版本。

Black box on the top right need to get in front of all layers, including overlay layer.

笨拙 - http://plnkr.co/edit/FEo8AQBBrh1YMHrduZeM?p=preview

HTML:

<body>
<div class="div1">div1
<div class="div1-1">div1-1
<div class="div1-1-1">
div 1-1-1
<div class="div1-1-1-1">
1-1-1-1
</div>
</div>
</div>
</div>
<div class="overlay"></div>
</body>

CSS:

body{color:#fff;}
.overlay{position:fixed; top:0; left:0; right:0; bottom:0; background:#000;opacity:.5; z-index:1005;}
.div1{width:100%; height:600px; background:red; position:relative;}
.div1-1 {width:auto; height:600px; background:blue; position:absolute; z-index:2; left:40px;
top:0; bottom:0; right:0;
}
.div1-1-1 {width:100%; height:40px; background:green; position:absolute; z-index:15;
top:0;right:0; left:0;
}
.div1-1-1-1 {width:40px; height:40px; background:black; position:absolute; right:0; top:0;}

最佳答案

我改变了很多结构,为了完成任务,请查看 Code here

CSS Code: /* Styles go here */

body{color:#fff;}
.overlay {
background: none repeat scroll 0 0 #000000;
bottom: 0;
left: 0;
opacity: 0.5;
position: fixed;
right: 0;
top: 0;
z-index: 20;
}
.div1{width:100%; height:600px; background:red; position:relative;}
.div1-1 {
background: none repeat scroll 0 0 #0000FF;
bottom: 0;
height: 600px;
left: 40px;
position: absolute;
right: 0;
top: 0;
width: auto;
}

.div1-1-1 {
background: none repeat scroll 0 0 #008000;
height: 40px;
left: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
.div1-1-1-1 {
background: none repeat scroll 0 0 #000000;
height: 40px;
position: absolute;
right: 0;
top: 0;
width: 40px;
z-index: 999;
}

HTML Code:

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>

<body>
<div class="overlay"></div>
<div class="div1">div1
<div class="div1-1">div1-1
<div class="div1-1-1">
div 1-1-1
<div class="div1-1-1-1">
1-1-1-1
</div>
</div>
</div>
</div>
<!--<div class="overlay"></div>-->
</body>

</html>

如果您有任何其他问题,请添加评论。

问候 D.

关于html - z-index - 将深层嵌套元素放在最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25033141/

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