I have a page where I want to achieve the following:
- I have a normal page, that I in some cases want to apply a backdrop to
- When the backdrop is active, I want a specific div to ble visible on top of the backdrop
This works great, untill I use this on my page where I'm using display: flex
I've produced a minimal example that shows the problem
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.backdrop {
position: fixed;
right: 0;
bottom: 0;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
}
.child {
background: #fff;
z-index: 3;
position: absolute;
}
header {
z-index: 1;
position: static;
}
.fullscreen {
/*display: flex;*/
}
</style>
</head>
<body>
<div id="root">
<div class="fullscreen">
<header>
should be below backdrop
<div class="child">should be above backdrop</div>
</header>
<div class="backdrop"></div>
</div>
</div>
</body>
</html>
this works as expected:
However, when I add display: flex to the fullscreen-div it does not work:
I realize that I could remove the display: flex, but this breaks other functionality on my site. Another option is to remove the z-index on the header-element, but this causes other issues.
So I'm kinda stuck trying to figure out how to solve this. Any ideas?