固定枠または動的枠をお探しですか? あなたのコードの問題は、W3C ボックス モデルです。デフォルトのモデルでは、要素のサイズにパディング、マージン、ボーダーが追加されます。したがって、コードで実際に言っているのは、「ボックスを 100% にしてから、10px 分の境界線を追加する」ということです。
通常、簡単な変更はボックス モデルを手動で切り替えることですが、残念ながら、そのプロパティは では適切に機能しませんheight: 100%
。したがって、いくつかのオプションがあります。
1) 固定された境界線を探している場合、これは良いトリックです: http://css-tricks.com/body-border/
2) 動的な境界線が必要な場合は、追加の高さボーダーが追加されます。1 つの方法を次に示します。
html,body { height:100%; padding: 0; margin: 0; }
#container {
min-height:100%;
border-right: 5px solid #000;
border-left: 5px solid #000;
position: relative; /* relative postion so we can absolutely position footer within it */
}
#header {
height: 100px;
border-top: 5px solid #000;
background-color: red;
}
#content { padding: 0 0 100px 0; } /*padding must be equal to the height of the footer*/
#footer {
height: 100px;
border-bottom: 5px solid #000;
background-color: blue;
position: absolute;
bottom: 0;
width: 100%; /* with absolute position, a width must be declared */
}
HTML
<div id="container">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
jsfiddle はこちら: http://jsfiddle.net/Qw2cb/