2013-10-10 67 views
0
<body>  
<div id='top'>this is top</div> 
some text... 
</body> 

CSS身体不是100%的高度

html{ 
    height:100%; 
    background:green; 
} 
body{ 
    max-width:50%; 
    height:100%; //doesn't work 
    background:red; 
    margin:0 auto; 
} 
#top{ 
    height:30px; 
    background:blue; 
} 

some text...body标签足够长,出现滚动条,body停止100%的高度。

无论文本的数量多少,我都需要将页面底部的彩色主体。

小提琴是here

+1

你在找什么浏览器?你有没有尝试添加最小高度:100%; – Jeffpowrs

+0

它看起来像你打算在Chrome中一样工作。 – Gray

回答

1

这里是不使用任何多余的元素的解决方案:

body{ 
    max-width:50%; 
    min-height:100%; // this is for when text does not go down to bottom of page 
    height: auto; // this is for when text overflows the page 
    background:red; 
    margin:0 auto; 
} 

这里是一个工作demo

1

您需要删除height: 100%;。无论文本数量多少,背景颜色都会保持红色。

jsFiddle

1

这可能不是最好的解决办法,但在这里是一种修复:

添加display:table;你的身体。

Fiddle

2

你应该使用其他<div>标签。

<div id="content">asdomasdosamd oasdimsad </div> 

和有这一个彩色太:

// css 
#content { background: red; } 

http://jsfiddle.net/4pxng/16/

+0

这绝对是最好的解决方案。 –