2013-08-18 195 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:自动。 –