Is there a way to make all elements in a row class the same height?

前端 未结 3 521
北海茫月
北海茫月 2020-12-13 07:36

In Bootstrap, is there an easy way to make all the span elements in a row the same height, i.e. the height of the tallest element?

Here\'s an example of what I mean.

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 07:45

    The resize event would have to be added to this code since the height of the content in most cases varies on different resolutions and that produces unwanted design problems like overflowed text.

    Here's an more complete version of the code that supports resizing as well

    jQuery(function () {
    
        equalMaxWidth = 500; /* Customize viewport width - for resolutions below this number, the height equalizing will not work */
        boxes = jQuery('.well');
    
        boxes.removeAttr('style');
        if(jQuery(window).width() > equalMaxWidth){
            equalBoxHeights(boxes);
        };
    
        window.onresize = function () {
            boxes.removeAttr('style');
            console.log( jQuery(window).width());
            if(jQuery(window).width() > equalMaxWidth){
                equalBoxHeights(boxes);
            };
        };
    });
    
    function equalBoxHeights(boxes) {
        maxHeight = Math.max.apply(
                Math, boxes.map(function () {
                    return jQuery(this).height();
                }).get());
        boxes.height(maxHeight);
    }
    

    Check the demo on jsFiddle http://jsfiddle.net/o4w7tjtz/

    Tip: try resizing the 3rd vertical frame (noticed equal heights on around 500pw width ?)

提交回复
热议问题