I'm having some trouble with the z-index. This is my simplified layout:
<div id="overlapper"></div>
<div id="container">
<div id="child1"></div>
<div id="child2"></div>
</div>
I need overlapper
to appear in front of child1
but behind child2
.
I tried messing around with z index but it didn't work, I think because of the stacking context.
Any help please? thanks
First, make sure that
overlapper
,child1
andchild2
belong to the same stacking context.That is, make sure
container
doesn't create a stacking context:container
must not be the root element.container
must have the default value forposition
,z-index
,opacity
andisolation
properties:position: static
orz-index: auto
opacity: 1
isolation: auto
Now, make
overlapper
,child1
andchild2
positioned elements, and addz-index
as you want.HTML
CSS
Fidle Here