I am trying to make the black box appear behind the oval-shaped element (parent). Therefore, I decided to use the z-index
, setting the parent's to a higher value than the child. However, the child is still appearing above the parent. I solved the issue by setting the child's z-index
to -1 and removing the z-index
property from the parent. But I don't understand why that works, what if I want to keep the z-index
property in the parent?
Here is my HTML:
<div id="x">
<div id="y"> </div>
</div>
Here is my CSS:
#x{
position: relative;
margin-top:40px;
height:400px;
width:250px;
border-radius: 40%;
margin-left: 30%;
background: linear-gradient(to bottom, #f5e050 78%, #517693 0%);
z-index:9999;
}
#y{
height: 5%;
width: 15%;
position: absolute;
top:97%;
left:36%;
background-color:black;
z-index: 1;
}