Почему красный div перед зеленым div, когда я удаляю z-index
от .wrapperRed
?Понимание z-index: Как этот элемент появляется перед своим родным родителем?
Похоже, что z-index
наследуется до цепочки.
Если я изменяю z-index
зеленого div на 6, он остается перед красным даже после удаления строки, описанной в первом предложении.
.wrapperRed {
height: 200px;
width: 200px;
position: absolute;
z-index: 1; /* Why is the red div in front of the green one, if this z-index is deleted? */
}
.red {
position: absolute;
height: 100%;
width: 100%;
background-color: red;
z-index: 5;
}
.green {
height: 200px;
width: 200px;
background-color: green;
position: absolute;
top: 100px;
left: 100px;
z-index: 1;
}
<div class="wrapperRed">
<div class="red"></div>
</div>
<div class="green"></div>
Смотрите https: //developer.m ozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context – j08691