天天看點

css3 高度最小100%,100%最小高度CSS布局

我正在使用以下代碼:CSS布局-100%的高度

最小身高

此頁面的#container元素的最小高度為100%。這樣,如果内容所需的高度大于視口提供的高度,則#content的高度也會強制#container變長。然後,可以使用#container上的背景圖像将#content中的可能列可視化;div不是表單元格,并且您不需要(或不需要)實體元素來建立這種視覺效果。如果您尚未确信;認為抖動的線條和漸變,而不是直線和簡單的配色方案。

相對定位

由于#container具有相對位置,是以#footer将始終保留在其底部;由于上述最小高度不會阻止#container縮放,即使#content強制#container變長,這也将起作用。

底部填充

由于不再存在于正常流程中,是以#content的填充底部現在為絕對的#footer提供了空間。預設情況下,此高度包含在滾動高度中,是以頁腳永遠不會與上述内容重疊。

稍微調整文本大小或調整浏覽器視窗大小以測試此布局。

html,body {

margin:0;

padding:0;

height:100%;

background:gray;

font-family:arial,sans-serif;

font-size:small;

color:#666;

}

h1 {

font:1.5em georgia,serif;

margin:0.5em 0;

}

h2 {

font:1.25em georgia,serif;

margin:0 0 0.5em;

}

h1, h2, a {

color:orange;

}

p {

line-height:1.5;

margin:0 0 1em;

}

div#container {

position:relative;

margin:0 auto;

width:750px;

background:#f0f0f0;

height:auto !important;

height:100%;

min-height:100%;

}

div#header {

padding:1em;

background:#ddd url("../csslayout.gif") 98% 10px no-repeat;

border-bottom:6px double gray;

}

div#header p {

font-style:italic;

font-size:1.1em;

margin:0;

}

div#content {

padding:1em 1em 5em;

}

div#content p {

text-align:justify;

padding:0 1em;

}

div#footer {

position:absolute;

width:100%;

bottom:0;

background:#ddd;

border-top:6px double gray;

}

div#footer p {

padding:1em;

margin:0;

}

對我來說很好。