I'm having three div
in my page.
- One parent (
z-index: 5
) - One sibling (of the parent) (
z-index: 10
) - One child (of the parent) (
z-index: 11
)
All the div
are using position: fixed
property.
My problem is the stacking order of the three elements.
I'm using the 'sibling' div
as a freeze layer in the app.
I want the sibling div
to be positioned between the parent and its child div
AFAIK, by using the position: fixed
property, we can position the divs anywhere in a page and use any stacking order.
But it's not working for my current scenario.
Please find the attached code:
.fixed {
position: fixed;
}
.outer {
top: 0;
left: 0;
bottom: 0;
right: 0;
background: yellow;
z-index: 5;
}
.child {
width: 200px;
height: 30px;
top: 0;
left: 50%;
transform: translateX(-50%);
background: red;
z-index: 11;
color: #fff;
}
.sibling {
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 10;
}
<div class="fixed outer">
<div class="fixed child">
I want this div to be on top
</div>
</div>
<div class="fixed sibling">
</div>