I have 3 divs:
If you set both div "one" and div "two" to have a height of 100%, you can control the height of both of them via the style of the outer div, and you are guaranteed that they always have the same height.
If you always want div "two" to be as high as div "one" or shorter, here's some JavaScript code that may help you:
document.getElementById("two").style.maxHeight = document.getElementById("one").style.height;
Using Javascript, you could do something like:
document.getElementById("two").style.height = document.getElementById("one").clientHeight;
This will work both if div one is higher then div two and the opposite (with jQuery) and will also be fired every time you resize the window (for fluid layouts):
resize_objects();
$(window).resize(resize_objects);
function resize_objects(){
var $a = $('#one').height(), $b = $('#two').height();
if($a > $b) {
//#one is higher than #two
$("#two").css("height",$a);
}
else {
//#two is higher than #one
$("#one").css("height",$b);
}
}
Via Javascript http://jsfiddle.net/D6bMJ/1/ (automatically set the #main height to the #one height) or CSS, manually define a height for the #main which would be the highest between #one and #two. : http://jsfiddle.net/D6bMJ/2/ (#two has height:100%, so the same height as it's parent).