I want green box to appear top of blue. The issue on my app is similar to this (lots of divs between the target and the root. z-index comes from one of the ancestors like this). I can't touch the ancestors nor the blue box which means I can't move the blue box or change the css properties of anything other than the green box. So, the div with z1 will have a lower z-index than the blue box. On the other hand I can do anything to green box. Is moving the green box out of there is the only solution?
.green, .blue {
position: absolute;
width: 100px;
color: white;
line-height: 100px;
text-align: center;
}
.green {
top: 20px;
left: 20px;
background: green;
}
.blue {
top: 60px;
left: 60px;
background: blue;
}
.relative {
position: relative;
}
.z1 {
z-index: 1;
}
.z10 {
z-index: 10;
}
.z100 {
z-index: 100;
}
<div>
<div class="z1 relative">
<div>
<div>
<div>
<div>
<div>
<span class="green z100">Green</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="z10 relative">
<span class="blue">Blue</span>
</div>