0
How do I leave the div #inner-block
in the foreground?
#block-1
{
position: absolute;
width: 200px;
height: 200px;
top: 10px;
left: 10px;
background-color: #999;
z-index: 1;
}
#inner-block
{
position: relative;
width: 100px;
height: 100px;
margin: 20px;
background-color: #777;
z-index: 100;
}
#block-2
{
position: absolute;
width: 200px;
height: 200px;
top: 60px;
left: 60px;
background-color: #666;
z-index: 2;
}
<div id="block-1"><div id="inner-block"></div></div>
<div id="block-2"></div>
Place
#block-1
with z-index greater than the#block-2
, or 3 or more.– Sam
z-index only works with position Absolute or Fixed elements
– Jasar Orion
It seems to me that the html structure used is not ideal for the purpose you want to get. Why
div
block-2
would be in the middle of the other two, despite being an element that does not relate to them in html ? Seems to be a structural problem– Isac
I agree with @Isac , How you want the child of an element to overlap with an element that is the brother of the father. This is not possible... In your case I believe you should put the div id="Inner-block" inside the div id="block-2". Note that the z-index hierarchy of the child id="Inner-block" refers to the father himself, not the father’s brother!
– hugocsl
Sam I need #block-3 to be in front of block-1 and before block-2
– Mano World
Block-2 and Hide are below block-3. What if you put block-1 first than block-3. Block-3 when it is in Sticky is below block-1.
– Mano World