Consider the following html and css:
<div class="page">
<div class="region">
<div class="zone">
Left
</div>
<div class="zone">
Center
</div>
<div class="zone">
Right
</div>
</div>
<div class="region">
<div class="zone">
Left
</div>
<div class="zone">
Right
<div id="overlay"></div> <!--- Overlay -->
</div>
</div>
<div class="region">
<div class="zone">
Left
</div>
<div class="zone">
Center
</div>
<div class="zone">
Right
</div>
</div>
</div>
.page {
background-color: #333;
height: 100vh;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
gap: 10px;
}
.region {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
padding: 10px 0px;
position: relative;
z-index: 0;
gap: 20px;
&:first-of-type {
padding-top: 0px;
height: 130px;
}
&:nth-of-type(2) {
height: calc(100vh - 245px);
}
&:last-of-type {
padding-bottom: 0px;
}
}
.zone {
display: flex;
flex-direction: column;
flex: 1;
flex-wrap: nowrap;
justify-content: flex-start;
gap: 10px;
padding: 0px 10px;
background-color: #0000ff33;
&:first-of-type {
padding-left: 20px;
}
&:last-of-type {
padding-right: 20px;
}
}
#overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1000;
background: #ffffff66;
}
Here’s a working example: https://codepen.io/a11smiles/pen/rNQoaPv
The problem is that the overlay covers the top
and middle
flex-boxes and their content. However, while the overlay is the full width and height of the screen, the footer
flex-box and its content is always on top (the overlay is behind the footer). Nothing that I’ve done has changed that. As you can see, I’ve tried setting the footer
‘s z-index explicitly to 0, but that doesn’t work either.
Any thoughts?
Thanks!
3
Answers
/* Rest of your CSS remains the same */
The problem with the overlay not covering the footer flex-box and its content is due to the stacking context created by the z-index property and the position property used in the CSS.
You can do this by adding position: relative; z-index: 1; to the .page class.This will create a new stacking context for the entire page, and an overlay with z-index: 1000 will appear on top of all elements in this new stacking context, including the footer flex-box.
Update your ‘.region’ style to this (also ‘&:last-of-type’)
To make the Overlay overlay the entire viewport either
Here’s the first solution: