簡體   English   中英

身體不是100%身高

[英]body is not 100% height

<body>    
<div id='top'>this is top</div>
some text... 
</body>

CSS

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

body標簽中的some text...足夠長而出現滾動條時, body停止為100%的高度。

無論頁面中有多少文本,我都需要在頁面底部添加彩色的正文。

小提琴在這里

您應該使用另一個<div>標簽。

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

並且也將這個顏色上色:

// css
#content { background: red; }

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

您需要移除height: 100%; 無論隨后的文本量如何,背景顏色將保持紅色。

的jsfiddle

它可能不是最好的解決方案,但這是一種解決方法:

添加display:table; 到你的身體。

小提琴

這是不使用任何額外元素的解決方案:

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;
}

這是一個工作示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM