I assumed until now that by default, according to the normal layout behavior, the <body>
element filled up 100% of the height of the container <html>
element even when position: static
was set.
However, a simple experiment proved my assumption wrong and I was shocked.
I do understand that in the normal layout behavior, block elements' heights are elastic and stretch to fill their entire contents. However, for some reason, I thought this did not apply to the <body>
element.
So, in my simple experiment, I have the following HTML:
html {
background-color: white;
}
body {
width: 50%;
background-color: gray;
margin: 0 auto;
min-height: 100%;
height: 100%;
/* position: absolute;
left: 22%; */
}
<h1>Nice sounds</h1>
<p>Zoo zoo zoo</p>
<p>Koo koo koo</p>
<p>Boo boo boo</p>
<p>Poo poo poo</p>
If I leave the position: absolute;
commented as it is just now, then by default, in the static layout, the body behaves just like any other block element and is only as tall to fill up its contents, ignoring the rules height: 100%;
and min-height: 100%
. It looks like the picture below.
If, however, I change the positioning to absolute
, i.e. if I uncomment the following:
position: absolute;
left: 22%;
Then of course, it obeys the height: 100%; min-height: 100%
rules. It then fills up the entire height of the browser like so:
Is this the normal behavior? Does the <body>
element behave just like any other block element with respect to its layout rules, esp. with respect to its height?