I am working on creating a webpage with three distinct sections:
- A fixed height header
- A fluid main section
- A fixed height footer
My goal is to ensure that the page has a minimum height so that the bottom of the footer aligns with the bottom of the window. I also want the main section to expand, even when the content within it is limited.
While I am aware that JavaScript can achieve this effect, I would prefer to find a CSS-based solution, if possible.
I have experimented with different versions of the following code snippet, but the main section is not expanding beyond the boundaries set by its content:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
body, header, main, footer {
width:100%;
display:block;
}
body{
display:block;
position:relative;
height:100%;
min-height:100%;
padding:0;
margin:0;
}
header{
background-color:#ccc;
height:100px;
}
footer{
height:100px;
background-color:#ccc;
}
main {
border:1px solid #f00;
}
#wrapper{
height:100%;
min-height:100%;
}
</style>
</head>
<body>
<div id="wrapper">
<header>
Header
</header>
<main>
Main
</main>
<footer>
Footer
</footer>
</div>
</body>
</html>