So I have three div’s
One parent and two child.
The parent is as follows:
#parent {
overflow:auto;
margin: 0 auto;
margin-top:37px;
min-height: 100%;
width:875px;
}
the two child divs are as follows
#child1 {
overflow:auto;
min-height:150px;
border-bottom:1px solid #bbb;
background-color:#eee;
opacity:0.4;
}
#child2 {
height:100%;
background-color:white;
}
The parent div extends 100% as I can see the borders of it till the end of the page but the child2 is not extending down to the end of the page like the parent div.
height doesn’t behave the way you seem to be anticipating. When you specify
height: 100%that percentage is calculated by looking up the DOM for the first parent of said element with a height specified that hasabsoluteorrelativepositioning.You can cheat when it comes to the body tag, so if you had something like this:
Some browsers/versions will behave the way you expect by taking up the total height of the page. But it won’t work when you go any deeper than that.
Here is the approach I use to strech a div to the bottom of the page, it involves absolute positioning (nice thing about this one is that it is pretty cross-browser compliant and doesn’t require javascript to pull it off):
Here is a Jsfiddle for demo: http://jsfiddle.net/t7ZpX/
The trick:
When you specify absolute positioning and then put in
bottom: 0;that causes the element to stretch to the bottom of the page; You just have to worry about positioning the elements as a trade off.