简体   繁体   English

CSS min-height不起作用

[英]CSS min-height doesn't work

I have a parent #out , and a child #in div. 我有一个父母#out和一个孩子#in div。 The parent is absolute positioned, and it's min-height is 100%. 父母是绝对定位的,它的最小高度是100%。 It works, but if I set min-height: 100% to the child too, then it has no result. 它有效,但是如果我将min-height:100%设置给孩子,那么它没有结果。

HTML: HTML:

<div id="out"><div id="in">foo<br/>bar</div></div>

CSS: CSS:

#out {
    position: absolute;
    min-height: 100%;
    background-color: green;
    width: 100%;
}
#in {
    min-height: 100%;
    background-color: red;
}

It works only in Opera JSfiddle link: http://jsfiddle.net/TPyKS/ 它仅适用于Opera JSfiddle链接: http//jsfiddle.net/TPyKS/

Absolute positioned elements are not computed in-line with other elements in the DOM. 绝对定位元素不是与DOM中的其他元素一起计算的。 They are treated as their own floating elements. 它们被视为自己的浮动元素。 The height/width of other elements means nothing to them. 其他元素的高度/宽度对他们来说毫无意义。 Thus, you are not able to set a percentage based min-height/min-width on them. 因此,您无法根据它们设置基于最小高度/最小宽度的百分比。 You would need to set the height/width explicitly. 您需要明确设置高度/宽度。

Add height: 100%; height: 100%; to #out #out

#out {
    position: absolute;
    min-height: 100%;
    background-color: green;
    width: 100%;
    height: 100%;
}

Working DEMO: http://jsfiddle.net/enve/TPyKS/1/ 工作演示: http//jsfiddle.net/enve/TPyKS/1/

Change of min-height :100% to height :100% on #out will work... min-height :100% to height :100% on #out变化min-height :100% to height :100% on #out将起作用...

updated fiddle : http://jsfiddle.net/TPyKS/2/ 更新小提琴: http//jsfiddle.net/TPyKS/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM