我正在尝试添加叠加层,但它无法按预期工作。
.overlay {
position: absolute;
background-color: rgba(0, 0, 0, 0.6);
z-index: -1;
width: 100%;
height: 100%;
}
.center-div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
}

<div class="center-div">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
</div>
<div class="overlay">
</div>
&#13;
我需要带有class center-div的div在class overlay之上。
这有什么问题?
答案 0 :(得分:0)
答案 1 :(得分:0)
.center-div
已高于.overlay
!。
尝试将background-color
添加到.center-div
以突出显示它。
.overlay {
position: absolute;
background-color: rgba(0, 0, 0, 0.6);
z-index: -1;
width: 100%;
height: 100%;
}
.center-div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
background-color: white;
}
<div class="center-div">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
</div>
<div class="overlay">
</div>