Div Height Equal To Another Div Max-height
Solution 1:
Using Javascript, you could do something like:
document.getElementById("two").style.height = document.getElementById("one").clientHeight;
Solution 2:
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;
Solution 3:
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).
Solution 4:
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);
}
}
Post a Comment for "Div Height Equal To Another Div Max-height"