Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS min-height doesn't work

Tags:

html

css

I have a parent #out, and a child #in div. The parent is absolute positioned, and it's min-height is 100%. It works, but if I set min-height: 100% to the child too, then it has no result.

HTML:

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

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/

like image 647
friction Avatar asked Feb 10 '13 17:02

friction


2 Answers

Absolute positioned elements are not computed in-line with other elements in the 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.

like image 100
Gerry Avatar answered Sep 28 '22 12:09

Gerry


Add height: 100%; to #out

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

Working DEMO: http://jsfiddle.net/enve/TPyKS/1/

like image 36
Enve Avatar answered Sep 28 '22 10:09

Enve