Find out divs height and setting div height

后端 未结 9 932
天涯浪人
天涯浪人 2020-12-14 21:41

I\'m quite new to javascript/jquery stuff, but i would like to do this kind of thing with it:

I have four divs side-by-side like this and content in each one. Now if

相关标签:
9条回答
  • 2020-12-14 22:11

    This is simple code

    var heights = $("element").map(function ()
    {
        return $(this).height();
    }).get(),
    
    MaxHeight = Math.max.apply(null, heights);
    

    or

    var highest = null;
    var hi = 0;
    $(".testdiv").each(function(){
    var h = $(this).height();
    if(h > hi){
       hi = h;
     highest = $(this);  
     }    
    });
    
    highest.css("background-color", "red");
    
    0 讨论(0)
  • 2020-12-14 22:14

    I believe you are looking for this plugin: equalizeBottoms by Ben Alman

    0 讨论(0)
  • 2020-12-14 22:16

    Well you can get and set the height with height()

    height = $('#id').height()
    

    Loop through the elements and check the height, e.g.:

    $elements = $('.container');
    
    var max_height = 0;
    
    for ($element in $elements) {
        if (max_height > $element.height()) max_height = $element.height();
    }
    
    $elements.height(max_height);
    
    0 讨论(0)
提交回复
热议问题