我想在CSS中放置一個簡單的3行佈局。它需要:粘頭,粘腳(可變高度),流體中間?
- 的主容器的div(100%的寬度,100%高度),其保持...
- 粘滯頭部(48像素的固定高度)
- 的中間部,填補所有剩餘空間之間的頁眉和頁腳
- 粘滯頁腳(62px的初始高度,但通過javascript頁面加載之後可以改變)
這裏是我到目前爲止有:
HTML
<body>
<div id="container">
<div id="headContainer">
...
</div>
<div id="bodyContainer">
Stuff goes here
</div>
<div id="footContainer">
...
</div>
</div>
</body>
CSS
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
body {
background-color:#2c3e50;
}
div#container {
height:100%;
width:100%;
}
div#headContainer {
background-color:#e74c3c;
height:48px;
width:100%;
z-index:1;
}
div#bodyContainer {
overflow:auto;
width:100%;
top:48px;
position:absolute;
background-color:#FFFFFF;
}
div#footContainer {
background-color:#c0392b;
width:100%;
position:absolute;
bottom:0;
padding:11px 18px;
box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* Safari */
}
我掙扎摸出我怎麼弄的'bodyContainer'填充頁眉和頁腳之間的可用空間。如果頁腳的大小是固定的,這會更容易!
任何提示?
你想在這個意義上粘頁腳,它會留在屏幕的底部,而不是與頁面滾動? – Coop
是的。所有內容都將位於bodyContainer中,應該可以滾動。頁眉和頁腳應分別保留在頁面的頂部和底部。 – Mike
@Coop我有這個問題!怎樣才能使它隨着滾動而移動?謝謝 – equisde