Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

http://jsfiddle.net/DVnZ6/

like image 823
DaveR Avatar asked Sep 08 '12 12:09

DaveR


People also ask

How do you make all col the same height?

As of 2017, the best (and easiest) way to make equal height columns in a responsive design is using CSS3 flexbox. Now we have columns that are equal in height, and their content fills the full height ot the entire column.

How do you make all divs the same height in CSS?

You can use Jquery's Equal Heights Plugin to accomplish, this plugins makes all the div of exact same height as other. If one of them grows and other will also grow.

How do I keep my divs the same height?

Place both DIVs into a container DIV that's set to 100% of page height and set both interior DIVS to 100%. They will fill up the container DIV and the height of both will be equal.

How do I keep two side by side DIV elements the same height?

Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.


2 Answers

You can do it using jQuery:

boxes = $('.well');
maxHeight = Math.max.apply(
  Math, boxes.map(function() {
    return $(this).height();
}).get());
boxes.height(maxHeight);

Here's an example: http://jsfiddle.net/DVnZ6/3/

like image 154
Francesco Frassinelli Avatar answered Oct 12 '22 23:10

Francesco Frassinelli


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 ?)

like image 28
dBlaze Avatar answered Oct 12 '22 21:10

dBlaze