Div height equal to another div max-height

前端 未结 4 1356
孤街浪徒
孤街浪徒 2021-01-16 03:49

I have 3 divs:

  • Div
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 04:29

    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);
        }
    }
    

提交回复
热议问题