This HTML structure has a div#page
, in which the current page content will be loaded via Ajax. The content always consists of section
tags, which can have a dynamic height (in percent relative to the browser) or a static height (in pixels).
The height of div#page
should adjust, so that the footer
will follow immediately after the last div#page > section
.
To be able to set a value in percent for the div#page > section
tags however, I gave div#page
a height of 100%. Therefore, it's DOM height won't stretch.
If the footer
tag was inside div#page
, it would work. This is not a good solution for me, because the footer would be overwritten by the dynamicaly loaded page content.
Is there some magic CSS solution to stretch the div#page
properly?
body, html { margin: 0; padding: 0; }
#outer { background: red; position: absolute; width: 100%; height: 100%; }
#page { height: 100%; }
#page > section { background: #666; width: 100%; }
#page > section:nth-of-type(2n) { background: #333; }
#page > section:nth-of-type(1) { height: 100%; }
#page > section:nth-of-type(2) { height: 160px; }
#page > section:nth-of-type(3) { height: 220px; }
#page > section:nth-of-type(4) { height: 120px; }
footer { background: green; height: 160px; }
<div id="outer">
<!-- The current page content will be loaded into this div. -->
<div id="page">
<section>Full height.</section>
<section>Static height 1.</section>
<section>Static height 2.</section>
<section>Static height 3.</section>
</div>
<!-- The footer is static and therefore not inside of the #page div. -->
<footer>
Immediately after static height 3.
</footer>
</div>