61

Here is an example of the issue in question:

http://dev.madebysabotage.com/playground/overlay.html

You see there is a gray overlay over the entire page, but if you scroll down, the content below the initial loaded page doesn't have the overlay.

I have an #overlay div and it seems it doesn't keep the 100% height during scrolling, so trying to figure out how to pull that off.

Here's the full source:

html {
  height: 100%;
  min-height: 100%;
}

body {
  height: 100%;
  min-height: 100%;
  font-family: Georgia, sans-serif;
}

#overlay {
  background: rgba(0, 0, 0, 0.4);
  width: 100%;
  height: 100%;
  min-height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10000;
}

header,
section,
footer {
  width: 800px;
  margin: 0 auto 20px auto;
  padding: 20px;
  background: #ff0;
}

section {
  min-height: 1500px;
}
<div id="overlay"></div>
<header>
  <h1>Header</h1>
</header>
<section>
  <p>Here's some sweet content</p>
</section>
<footer>
  <p>Here's my footer</p>
</footer>
Run_Script
  • 2,487
  • 2
  • 15
  • 30
Shpigford
  • 24,748
  • 58
  • 163
  • 252
  • Thanks for this! For anyone else reading, the problem is fixed at the link above. To recreate it use Firebug or similar to remove `position:fixed;` from the overlay id :) – RyanM Nov 07 '12 at 20:05
  • 1
    3yrs later and I have a same problem :) +1 for question – I am Cavic Apr 04 '14 at 02:24

3 Answers3

177

position: fixed; on the overlay.

Vivek
  • 11,938
  • 19
  • 92
  • 127
benhowdle89
  • 36,900
  • 69
  • 202
  • 331
10

Change #overlay position:absolute to position:fixed

BadHorsie
  • 14,135
  • 30
  • 117
  • 191
Bazzz
  • 26,427
  • 12
  • 52
  • 69
5

This happens because the #overlay position: absolute is relative to the <html> and using it's dimensions, which is only the viewport height.

To make sure that the #overlay uses the dimensions of whole page, you could use position: relative; on the <body> (but you will need to remove the min-height: 100% and height: 100% on the <body> first because this makes it use the viewport size). The #overlay will then use the <body> dimensions and fill the entire page.

Thom
  • 84
  • 1
  • 4