重複の可能性:
CSS - 高さのパーセンテージ
3 つの div の中間の div を使用可能なスペースの 100% に収めることができません。
<body>
<div id="container">
<div id="header">
</div>
<div id="content">
</div>
<div id="footer">
</div>
</div>
</body>
私のCSSは次のとおりです。
html, body {
margin: 0;
padding: 0;
border:1px;
vertical-align:top;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:14px;
color:#333;
height: 100%;
}
#container {
height: 100%;
width: 100%;
}
#header {
height: 100px;
width: 100%;
background: #069;
}
#content {
height: 100%;
width: 100%;
background: #F60;
}
#footer {
height: 75px;
width: 100%;
background: #060;
}
中央の div は実際には 100% ですが、使用可能なスペースに適合していません。
次のようなことをしています: 画面が 500px の場合
30px
100% (500px)
30px
私が必要とするのは:
30px
100% (460px)
30px
これはJavaScriptを使わなくても可能ですか?
どうもありがとう
編集:
申し訳ありませんが、ヘッダー、ミドル、フッターの 3 つの要素がある高さを意味していました。ヘッダーとフッターの高さは固定されていますが、使用可能なすべてのスペースに中央を合わせたい
他のスタックオーバーフローの質問に基づいて別の解決策を見つけました:
* { margin: 0; padding: 0 }
html, body {
margin: 0;
padding: 0;
vertical-align:top;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:14px;
color:#333;
height: 100%;
border: 0;
}
#header
{
height: 100px;
background:#C60;
}
#container
{
min-height: 100%;
height: auto !important; /*Cause footer to stick to bottom in IE 6*/
height: 100%;
margin: 0 auto -100px; /*Allow for footer height*/
vertical-align:bottom;
background:#096;
}
#footer
{
height: 100px; /*Push must be same height as Footer */
background:#C60;
}
HTML
<body>
<div id="container">
<div id="header"> </div>
<div id="content"> </div>
</div>
<div id="footer"> </div>
</body>