2

HTML:

<div id="a">
  <div id="b">
  </div>
</div>

CSS:

  html, body {
    height: 100%;
    background: red;
    margin: 0;
  }
  #a {
    min-height: 100%;
    background: green;
  }
  #b {
    min-height: 100%;
    background: yellow;
  }

http://jsfiddle.net/otpxvb2u/

Why does the browser display green and not yellow?

mushroom
  • 1,909
  • 3
  • 16
  • 33

6 Answers6

2

This combination simply can’t work.

Your outer element has a min-height – that means, it’s height actually depends on it’s content. If the content was larger than the 100%, then the actual height of the outer element would be more than those 100% the min-height specifies.

But now you want the inner element’s height to be a min-height of 100% as well – so the inner element would have to look for the outer element to determine its actual height, and the same thing the other way around for the outer element. That equation is just not solvable.

So you need to set an explicit height for the outer element: height:100%

EDIT pertaining to your comment:

Any explanation for why @George's work-around works?

height:1px acts as a kind of “starting value” for the equation.

The inner element has a definitive height to start with now, 1px – so for the outer element, the minimum of (100%, height-determined-by-height-of-child-element) can be determined now – and that will result in 100% (of the height of the parent of that outer element, body), which leads to a specific pixel value as the calculated value.

And now the min-height:100% for the inner element can kick in as well – the outer element has an effective value in pixels now, and so the minimum of (100% of that-pixel-value, 1px) can be calculated for the inner element as well, which will result in that same pixel value as the outer element has effectively.

CBroe
  • 91,630
  • 14
  • 92
  • 150
0

Use height instead of min-height

#a {
    height: 100%;
    background: green;
}
#b {
    height: 100%;
    background: yellow;       
}

Updated DEMO

Carl0s1z
  • 4,683
  • 7
  • 32
  • 47
0

To inherit the hight, the parent element need a height definition. So add the height attribute to the parent.

#a {
    height: 100%;
    min-height: 100%;        
    background: green;
}

Fiddle

Steven Web
  • 1,966
  • 13
  • 23
0

or may be you can fix the min-height in pixel

 #b {
    min-height: 200px;
    background: yellow;
  }

check the fiddle http://jsfiddle.net/otpxvb2u/4/

supersaiyan
  • 1,670
  • 5
  • 16
  • 36
0

Provide the height to #b

#b {
height: 100px;
....
....

or

give height: 100%; to #a and #b

#a,#b{
height:100%;
....
....
Punitha Subramani
  • 1,467
  • 1
  • 8
  • 6
0
#a
{
height:auto;
}

#b
{
height:auto;
min-height:200px;
}
Shen Shen
  • 72
  • 2
  • 12