今回はfooterを常に最下部に表示させる方法です。
これまたよくある話だけど、いつもスムーズにできずに時間がかかってしまう。
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
}
#container {
position: relative;
width: 100%;
/* コンテンツ部分の高さが画面に収まらない場合はコンテンツの高さに合わせる*/
height: auto !important;
/* コンテンツ部分の高さが画面より低い場合は画面の高さに合わせる*/
height: 100%;
min-height: 100%;
background-color: blue;
}
#header {
width: 100%;
height: 40px;
background-color: green;
}
#contents {
width: 100%;
height: 100px;
background-color: yellow;
padding-bottom: 40px;
}
#footer {
/* containerからの絶対位置を定義 */
position: absolute;
bottom: 0;
width: 100%;
height: 40px;
background-color: red;
}
</style>
</head>
<body>
<div id="container">
<div id="header">header</div><!-- /#header-->
<div id="contents">contents</div><!-- /#contents-->
<div id="footer">footer</div><!-- /#footer -->
</div><!-- /#container-->
</body>
</html>