Twitter Bootstrap 3 - Panels of Equal Height in a Fluid Row

后端 未结 6 2016
再見小時候
再見小時候 2020-11-29 03:24

I am new to Bootstrap 3 and I would like to have 3 panels on my landing page of equal height, even though the middle panel has less content. When resized they become the sam

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 04:02

    this function finds the largest .panel-body height, then makes that the height of all my .panel-body elements.

    function evenpanels() {
        var heights = [];                           // make an array
        $(".panel-body").each(function(){           // copy the height of each
            heights.push($(this).height());         //   element to the array
        });
        heights.sort(function(a, b){return b - a}); // sort the array high to low
        var minh = heights[0];                      // take the highest number    
        $(".panel-body").height(minh);              // and apply that to each element
    }
    

    Now that all the panel-bodys are the same, the heights need to be cleared when the window resizes before running the "evenpanels" function again.

    $(window).resize(function () { 
            $(".panel-body").each(function(){
                $(this).css('height',"");           // clear height values
            });                                     
            evenpanels();
    });
    

提交回复
热议问题