Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML overlay not covering flexbox layout

Tags:

html

css

I have an HTML/CSS pure layout and I'm using flexbox. I am developing a simple hamburger overlay menu sort of thing, but the overlay isn't fully covering the entire site -- there is no higher z-index present.

If I change the opacity to 0, the entire page goes white.

Desired Output:

Div that covers the entire page

Current Output (See Below):

HTML

<body data-theme="light" class="overlay">
...
</body>

CSS

.overlay {
  opacity: 1;
  background: #000;
  width: 100%;
  height: 100%;
  z-index: 10;
  top: 0;
  left: 0;
  position: fixed;
}

Output

enter image description here

like image 291
Ryan Avatar asked Jul 10 '26 02:07

Ryan


1 Answers

You can't make the HTML body an overlay because it is the main container for the whole page, so it contains the elements you are trying to overlay.

Instead you can create a separate div for the overlay. This shouldn't have any content (unless you want content in your overlay of course). Then you can add your existing overlay class to it:

.overlay {
  opacity: 0.5;
  background: #000;
  width: 100%;
  height: 100%;
  z-index: 10;
  top: 0;
  left: 0;
  position: fixed;
}
h1, p { color: red;}
<body data-theme="light">
    <div class="overlay"></div>
    <h1>Hello</h1>
</body>
like image 123
FluffyKitten Avatar answered Jul 19 '26 00:07

FluffyKitten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!