1

Why is body, html, and #black sizing to the size of the viewport and not the document height?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<style>

html, body{
height:100%;
}


#black{
position:absolute;
width:100%;
min-height:100%;
height:100%;
background-color:#000000;
z-index:1000;
}

#shell{
height:962px;
width:972px;
margin:0 auto;

}
</style>

</head>

<body>
<div id="black"></div>

<div id="shell">


</div>

</body>
</html>
Guesser
  • 1,769
  • 3
  • 25
  • 52

3 Answers3

1

You set your body and html tags to height: 100%. This "locks" them to the viewport height and then #black inherits that height. You need to use min-height:

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

UPDATE:

Forgot to mention something. Add this as well:

body {
    position: relative;
}
Per Salbark
  • 3,597
  • 1
  • 23
  • 24
0

Try this:

body, html {
    padding: 0;
    margin: 0;
}

EDIT:

#black {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%:
}
Tony Dinh
  • 6,668
  • 5
  • 39
  • 58
  • @user1209203 I have saved your html as a file using my css and it works. The black color fills all the page. – Tony Dinh Oct 29 '13 at 15:51
  • So then scroll down and it ends at the viewport height – Guesser Oct 29 '13 at 15:52
  • @TrungDQ: Try resizing your browser window to less than 962px height. You get a scoll bar and white space below the black. – Per Salbark Oct 29 '13 at 15:52
  • @user1209203 I have updated my answer. Then you can see the black everywhere. That is the only way I can think about if you don't want to move your `#shell` into the `#black`. – Tony Dinh Oct 29 '13 at 16:03
  • Not on Opera mobile though :( – Guesser Oct 29 '13 at 16:16
  • @user1209203 according to this answer http://stackoverflow.com/a/7851316/1420186 you may need to update your browser. But I always wonder why don't you use `body { background-color: black; }`. – Tony Dinh Oct 29 '13 at 16:18
  • the black is and overlay to fade from black – Guesser Oct 29 '13 at 16:37
-1

Because you said so. Saying

#black {
    position: absolute;
    width: 100%;
    height: 100%;
}

does set width and height to 100% of the containing block's size. The containing block in this case is the viewport.

When you want #black to cover the whole content, you must give it a different containing block. This can be done by positioning body

body {
    position: relative;
}

Now it covers the height. To do the same for the width, you can either set a width on body

body {
    position: relative;
    width: 972px;
}

or float body

body {
    position: relative;
    float: left;
}

See full JSFiddle

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198