Same height column bootstrap 3 row responsive

后端 未结 16 1744
难免孤独
难免孤独 2020-11-30 00:04

Hi I have four divs in a bootstrap row. I want all divs in this row to have the same height and not break responsibility. I don\'t know how to do this without breaking respo

16条回答
  •  温柔的废话
    2020-11-30 00:33

    I had same kind of situation wherein each column within a row should be of same height. By considering above answers and with little trick, it was easy to implement and resolve the issue of window resize also.

    $(document).ready(function() {
        //Initiate equalize on load
        equalize();
    });
    
    //Equalize on resizing of window
    $(window).resize(function() {
        removeHeights();
        equalize();
    });
    
    function equalize(){
    
        $(".container .row").each(function() {
            var heights = $(this).find("p").map(function() {
              return $(this).height();
            }).get(),
    
            maxHeight = Math.max.apply(null, heights);
    
          $(this).find("p").height(maxHeight);
    
        });
    }
    
    function removeHeights(){
    
        $(".container .row").each(function() {
    
          $(this).find("p").height("auto");
    
        });
    }
    

    Check the demo here - https://jsfiddle.net/3Lam7z68/ (Resize the output pane to see the each div column size's changing)

提交回复
热议问题