2013-08-18 194 views

回答

4

嘗試浮動頭:

#head { 
    background: green; 
    float: left; 
    width: 100%; 
} 
+1

這是非常有創意和簡單。愛它! – Itay

2

浮動頭正常工作(不知道爲什麼在布萊斯的答案downvotes)。

HTML:

<div id="parent"> 
    <div id="head">head<br />head<br />head<br /></div> 
    <div id="content">content</div> 
</div> 

CSS:

html, body { 
    margin: 0px; 
    height: 100%; 
} 
#parent { 
    background: red; 
    height: 100%; 
} 
#head { 
    background: green; 
    width: 100%; 
    float: left; 
} 
#content { 
    background: yellow; 
    min-height: 100%; 
} 

和工作JSFiddle

[編輯] 將height#content更改爲min-height

+1

對於'#content'元素,您應該使用'min-height:100%'而不是'height'來修復背景色問題。 http://jsfiddle.net/qolami/cMqTd/4/ –

+0

@HashemQolami,你是對的,也看到了我自己,並修復它:) – LinkinTED

+0

當我把長的內容放入內容div並將其設置爲溢出-y:自動。 –