[英]z-index on absolute div
我有兩個 div,A 和 B:
<div class="a">
A
</div>
<div class="b">
b
</div>
我希望 div B 位於 div A 之后。我不想更改標記的順序。
我試過 z-index,但沒有運氣。
.a{
background: gold;
height: 100px;
border-bottom: 2px solid red;
z-index: 99;
}
.b{
background: blue;
position: absolute;
width: 100%;
height: calc(100% - 100px);
transform: translateY(-10px);
z-index: 98;
}
給出position: relative
對於“a”將解決您的問題。 演示
z-index 僅適用於position:relative
。
.a{
background: gold;
height: 100px;
border-bottom: 2px solid red;
z-index: 10;
position:relative;
}
.b{
background: blue;
position: absolute;
width: 100%;
height: calc(100% - 100px);
transform: translateY(-10px);
z-index: 1;
top: 0;
}
只需將 b 類的 z-index 更改為 -1
.b{
background: blue;
position: absolute;
width: 100%;
height: calc(100% - 100px);
transform: translateY(-10px);
z-index: -1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.