0

I'm having a problem with positioning multiple div elements. I have three div elements in a row with different heights. But in "div 1" is slide-down menu, so the height of "div 1" changes. I want to know, how can I automaticly set the height of all three div elements to be the same.

4

4 回答 4

1

This jQuery plugin will set the height of each element in a set to the height of the tallest one:

// Sets the height of a set to the height of the tallest member.
$.fn.sizeToTallest = function () {
    var tallest = 0;
    this.each(function () {
        var h = $(this).height();
        if (h > tallest) tallest = h;
    });
    this.height(tallest);
    return this;
};

Use it like this:

$("myDivs").sizeToTallest();
于 2012-10-29T21:13:06.050 回答
0

Sounds like on the callback function for the slide-down of the one div, you just need to:

// grab the new hight
var newHeight = $(this).outerHeight();

// set it to the other two divs
$('.otherDivs').height(newHeight);
于 2012-10-29T21:12:35.850 回答
0
$height = "50px"; // or whatever height you wish


 $("div").each(function(e)
 {
    $(this).css("height",$height);
 });

The each function will iterate your divs and then set their heights to 50px

于 2012-10-29T21:13:48.137 回答
0
$('#div1').slideDown(400, function() {
    $('#div2, #div3').height($(this).height());
});
于 2012-10-29T21:21:16.980 回答