I have 3 divs: #parent
, child
, second
I want the #parent
div to be on top of #child
div and #child
div to be on top on #second
div.
How can I set the z-index
or configure the divs to achieve this?
Right now, the #child
div is on top of both.
I prefer not to change the HTML code and simply fix it with CSS.
I've checked other similar questions but none have been able to provide a solution to the problem I'm facing.
#parent, #child, #second{
height: 50px;
}
#parent{
background-color: grey;
position: relative;
z-index: 1;
width: 500px;
}
#child{
background-color: #216583;
color: white;
position: absolute;
top: 50%;
z-index: 0;
width: 400px;
}
#second{
background-color: #f76262;
position: relative;
z-index: -1;
width: 300px;
}
<div id="parent">
<div id="child">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, velit!</p>
</div>
</div>
<div id="second"></div>