Same height column bootstrap 3 row responsive

后端 未结 16 1740
难免孤独
难免孤独 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:34

    I'm a bit late to the game, but....

    This will align the heights of items in a row with a class of "row-height-matched". It matches the cells based on their top value so if they move underneath each other when the page gets smaller, I don't set the height.

    I know there are a number of CSS versions out there, but all of them break my layout design.

    $(window).resize(function () {
        var rows = $(".row.row-height-matched");
    
        rows.each(function () {
            var cells = $(this).children("[class^='col-']");
    
            cells.css("height", "");
    
            var j = [];
    
            cells.each(function () {
                j.push($(this).offset().top);
            });
    
            var u = $.unique($(j));
    
            u.each(function () {
                var top = $(this)[0];
    
                var topAlignedCells = cells.filter(function () {
                    return $(this).offset().top == top;
                })
    
                var max = 0;
    
                topAlignedCells.each(function () {
                    max = Math.max(max, $(this).height());
                })
    
                topAlignedCells.filter(function () {
                    return $(this).height() != max;
                }).height(max);
            })
    
        })
    })
    

提交回复
热议问题