ここがメイン領域です。コンテンツが少ない時もフッターは最下部にあります。コンテンツが増えるとそれに従ってフッターも追従し、スクロールできるようになります。
<style type="text/css">
html{
position: relative; /* relative */
min-height: 100%; /* min-height: 100%にする */
margin: 0px;
padding: 0px;
font-size: 67.5%;
}
body{
margin: 0px;
padding: 0px;
background-color: yellow;
}
#container{
background-color: green;
border: 1px solid red;
}
#header{
height: 100px;
background-color: red;
}
#header h1{
font-size: 3.2em;
}
#main{
font-size: 1.5em;
margin-left: 10px;
margin-right: 10px;
margin-bottom: 100px; /* ここがミソ!footerの高さと同じにする。*/
padding: 10px;
background-color: #CCC;
}
#footer{
position: absolute; /* htmlに対して固定 */
bottom: 0;
width: 100%;
height: 100px;
color: #fff;
background-color: #000;
line-height: 100px;
}
#footer p{
font-size: 1.5em;
margin: 0px;
text-align: center;
}
pre{
display: none;
}
</style>
追加してもフッターに被らないように、mainのmargin-bottomにfooterと同じ高さを設定します。
黄色はbody、緑はcontainer、グレーはmain、赤はheader。