タイトルdiv、コンテンツdiv、フッターdivがあるとします。
<div id="header">
Title
</div>
<div id="content" style="background:red">
<p>TEST</p>
</div>
<div id="footer">
footer
</div>
タイトルdivを常に20%、コンテンツを70%div、フッターを10%に設定するにはどうすればよいですか?
ありがとう
HTML:
<!DOCTYPE html>
<body>
<div class="container">
<div id="header" style="background:blue">
Title
</div>
<div id="content" style="background:red">
<p>TEST</p>
</div>
<div id="footer" style="background:gray">
footer
</div>
</div>
</body>
</html>
CSS:
* {
margin: 0;
padding: 0;
}
html,
body,
.container {
height: 100%;
}
#header {
height: 20%;
}
#content {
height: 70%;
}
#footer {
height: 10%;
}
あなたは絶対的なポジショニングでそれを行うことができます:
#header {
position: absolute;
top: 0;
height: 20%;
left: 0;
width: 100%;
}
#content {
position: absolute;
top: 20%;
height: 70%;
left: 0;
width: 100%;
}
#footer {
position: absolute;
top: 90%;
height: 10%;
left: 0;
width: 100%;
}
実際の動作については、 JSFiddleスニペットを参照してください。
これを試してください:http://jsfiddle.net/9gHY4/2/
#header {
position: absolute;
height: 20%;
width: 100%;
top: 0;
background-color: blue;
}
#content {
position: absolute;
top: 20%;
height: 70%;
width: 100%;
background-color: red;
}
#footer {
bottom: 0;
position: absolute;
height: 10%;
width: 100%;
background-color: green;
}