1134

I'm using Bootstrap. How can I make three columns all the same height?

Here is a screenshot of the problem. I would like the blue and red columns to be the same height as the yellow column.

Three bootstrap columns with the center column longer than the other two columns

Here is the code:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
    <div class="col-xs-4 panel" style="background-color: red">
        some content
    </div>
    <div class="col-xs-4 panel" style="background-color: yellow">
        catz
        <img width="100" height="100" src="https://lorempixel.com/100/100/cats/">
    </div>
    <div class="col-xs-4 panel" style="background-color: blue">
        some more content
    </div>
</div>
</div>
Cave Johnson
  • 6,499
  • 5
  • 38
  • 57
Richard
  • 62,943
  • 126
  • 334
  • 542
  • http://stackoverflow.com/questions/24745966/twitter-bootstrap-responsive-block-heights/ – trante Jul 15 '14 at 06:22
  • 3
    The example on Bootstrap breaks responsiveness Eduard. The flex `.row` is missing `flex-wrap: wrap;`. Here's an example of it working with responsiveness: http://codepen.io/bootstrapped/details/RrabNe/ – Bryan Willis Jan 12 '16 at 02:16
  • Possible Workaround – A Transparent image 1 pixel wide in the other columns. This new one pixel width image matches the pixel height of the cats pic in the above example. (May not work or be practical in your situation) – Sql Surfer Jan 17 '18 at 15:39
  • In Bootstrap 4, we can use the card for the same – Amjad Rehman A Jul 19 '18 at 13:00
  • the same way you make any block element a specific height? – Emobe Apr 30 '19 at 09:40
  • working solution - https://www.codeply.com/p/bCpAPuS0LL – Alex Oct 24 '21 at 16:03

34 Answers34

1168

LATEST SOLUTION (2022)

Solution 4 using Bootstrap 4 or 5

Bootstrap 4 and 5 use Flexbox by default, so there is no need for extra CSS.

Demo

<div class="container">
    <div class="row ">
        <div class="col-md-4" style="background-color: red">
          some content
        </div>
        <div class="col-md-4" style="background-color: yellow">
          catz
          <img width="100" height="100" src="https://placekitten.com/100/100/">
        </div>
        <div class="col-md-4" style="background-color: green">
          some more content
        </div>
    </div>
</div>

Solution 1 using negative margins (doesn't break responsiveness)

Demo

.row{
    overflow: hidden; 
}

[class*="col-"]{
    margin-bottom: -99999px;
    padding-bottom: 99999px;
}

Solution 2 using table

Demo

.row {
    display: table;
}

[class*="col-"] {
    float: none;
    display: table-cell;
    vertical-align: top;
}

Solution 3 using flex added August 2015. Comments posted before this don't apply to this solution.

Demo

.row {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display:         flex;
  flex-wrap: wrap;
}
.row > [class*='col-'] {
  display: flex;
  flex-direction: column;
}
Popnoodles
  • 28,090
  • 2
  • 45
  • 53
  • 8
    Think of it as the column being sucked into negative space. If you remove the overflow you'll see what's going on. – Popnoodles Oct 31 '13 at 11:50
  • 1
    It works but has a problem if you need to absolutely positioning some element at the bottom: it's hidden by the overflow. Nested elements neither can't determine the actual visible height, without javascript. – itsjavi Feb 11 '14 at 11:55
  • @mjolnic good point. I'd like to find a better solution. I would have thought height 100% and display block might help. – Popnoodles Feb 11 '14 at 19:24
  • it works in Firefox for me. Can you share your code? – Popnoodles Mar 25 '14 at 00:17
  • 9
    If targeting the bootstrap column class specifically you should probably use an anchor ^ instead of a wildcard *. Using ^ will say that the class must start with col- where as the wildcard shown will match any class with col- anywhere in the string, possibly having undesired effects on styles where you may have used the convention col-. (i.e. stuff-col-morestuff). – LiquaFoo Jun 05 '14 at 16:46
  • @LiquaFoo I agree but that's how bootstrap's selector is. – Popnoodles Jun 05 '14 at 18:53
  • 1
    It works only with single line of blocks. For more block, it ads them in right side again until it brakes view zone. – Gediminas Šukys Jul 23 '14 at 12:34
  • @Popnoodles I can share my code http://stackoverflow.com/questions/25000554/firefox-workaround-for-position-for-table-cell-element – Ray Aug 04 '14 at 09:31
  • This is working but my col-xs-12 is being ignored now.. How do i fix that? – Miguel Stevens Aug 13 '14 at 13:40
  • 4
    Solution 1 can make width problems – Mike Boutin Feb 05 '15 at 15:29
  • 8
    Nice answer, with some caveats. Solution 1 disables the float and therefore breaks the bootstrap grid responsive behavior. Solution 2 (explained in greater depth in http://www.positioniseverything.net/articles/onetruelayout/equalheight) doesn't show the bottom border (as it is clipped somewhere in the padding space). – Ohad Schneider Feb 06 '15 at 16:35
  • Hello, I am facing the same problem. But after I tried the solutions, the column does not seems to be responsive. How to fix that? – fyr91 Feb 08 '15 at 12:19
  • Solution2 is responsive in my case but not the first one who occured some bug with bootstrap 3 – LedZelkin Feb 08 '15 at 17:31
  • I found a problem with solution 2: if there are elements with attr `id="xxx"` and users jump to the ID, contents above the element fail to display ([demo](http://pastie.org/9945803): paste the codes to a local html file, open it with ".../xxx.html#p3"). Solution 1 seems working fine, hope I won't find any issue with it. – ZZY Feb 14 '15 at 03:56
  • 1
    @Notflip, I faced the same issue that "col-xs-12" doesn't make the next "col" to next line. My workaround is to apply solution 1 only to >= small device, as `@media(min-width:768px) { Solution 1 }` – ZZY Feb 16 '15 at 14:18
  • 5
    Non of this solutions working at all. 1) destroys bs3 grid responsive not working since float:none 2) this solution isn't doing cols same size in responsive, here is demonstration: http://www.bootply.com/SmpoLAKqO1 – zajca May 14 '15 at 08:30
  • Actually there are two thing what you could want, one is simple same col height without responsive, for this is best solution 2. Other one is to avoid jumping of col if text change height of one col to another, for this is best this solution -> http://stackoverflow.com/a/24747063/1269774. If you want both, use javascript or flexbox or write your own grid using table. – zajca May 14 '15 at 09:08
  • in case of two columns when resize browser screen (on mid, sm etc) first columns hides... why ?? how to fix it – Zain May 27 '15 at 06:18
  • +1 Only for the second solution because it does not break the Bootstrap responsiveness. Any answer that does is useless when dealing with *Bootstrap*. – Christine268 Jun 04 '15 at 01:38
  • Solution ! did work for me. But I had to add the `!important` to margin. Like this: `margin-bottom: -99999px !important;` – Anish Nair Oct 12 '15 at 06:47
  • 23
    Solution 3 breaks row responsiveness. – SPRBRN Oct 15 '15 at 10:40
  • 2
    These are all great examples for equal height columns although in this situation they all break the bootstrap grid framework. You should never do this explicitly to the row and column classes. Add your own class. The first one, while effective for fluid layouts is not good for responsive layouts as it applies all columns height to the height of the `.row` even if their not on the same row. The second one is missing styles and should not use BS columns as table cells. Tables are meant to use `border-spacing` while bootstrap `col-` classes use padding for their spacing. Using together wont work. – Bryan Willis Dec 20 '15 at 13:07
  • 11
    @Popnoodles you should add `flex-wrap: wrap;` to the third example to enable responsiveness. You also will want to add display: flex; flex-direction: column; to the column class. If you are going to use .row and not a custom class, you'll need to provide a fallback for older browsers changing the display flex back. Here's an [example](http://codepen.io/bootstrapped/full/RrabNe/) – Bryan Willis Dec 20 '15 at 13:13
  • I tried to make it out each method, but none of them work, here is my demo: [DEMO](http://demo.vrs-factory.pl/gl/) – Damian Apr 04 '16 at 21:20
  • @bwillis what does exactly do `display: flex; flex-direction: column;` in the column class? It seems to do nothing noticeable. – Watchmaker Apr 26 '16 at 16:33
  • The 3rd solution is close, but in IE 11 the stacked divs seem to be too wide, and in FF the stacked divs have different widths. – Matthew Lock May 18 '16 at 04:41
  • Solution 1 hides the bottom border. – johntrepreneur May 25 '16 at 23:12
  • I prefer solution 2, and I add width: 100% for .row – David Qin Jun 15 '16 at 04:14
  • @LoganG. ^ does not work for this class =" test col-md-2" – Eugen Konkov Jul 05 '16 at 10:01
  • @HakamFostok These solutions have worked for 100s of others hence the upvotes. Feel free to post a new question with your bad code so that someone can advise where you have misunderstood. – Popnoodles Nov 03 '16 at 16:58
  • None of the solutions, that work for 100s of others, work against *your* code, yet, despite the principal of Occam's razor, your wish is to downvote this answer multiple times. Hardly fair. – Popnoodles Nov 03 '16 at 18:56
  • Solution 3: flex-wrap: wrap breaks on safari-mobile. I removed it and it works for me – Patrick Nov 09 '16 at 13:33
  • 1
    Negative margin works the best. The other two solutions break the responsive property (will not wrap on small screen) – Ting Yi Shih Jan 19 '17 at 03:28
  • 6
    Solution 3 doesn't work in Safari. `.row::before { display: block; }` fixes that but I'm not sure why. – Rudey Jan 30 '17 at 15:28
  • 1
    `table-cell` or `negative margins` [don't really work](https://medium.com/wdstack/bootstrap-equal-height-columns-d07bc934eb27) when it comes to responsive design – Carol Skelly Mar 14 '17 at 23:45
  • Hello... no solutions worked for me. Can you see the snippet here please? https://stackoverflow.com/questions/72794658/how-to-set-all-elements-inside-a-row-to-be-the-same-height – jstuardo Jun 29 '22 at 01:22
  • @jstuardo that's because you're doing something else. You have cards and rows and div inside the columns, which are 100%, but aren't setting anything to height 100% to fix that. – Popnoodles Jun 29 '22 at 11:35
  • I had to use flex-direction: inherit; in the columns as well – cirrus3d May 14 '23 at 07:46
412

Update 2021

Bootstrap 4 + 5

Flexbox is now used by default in Bootstrap 4 (and Bootstrap 5) so there is no need for the extra CSS to make equal height columns: https://www.codeply.com/go/IJYRI4LPwU

Example:

<div class="container">
    <div class="row">
        <div class="col-md-6"></div>
        <div class="col-md-6"></div>
    </div>
</div>

Bootstrap 3

Best approach for Bootstap 3.x — using CSS flexbox (and requires minimal CSS)…

.equal {
  display: flex;
  display: -webkit-flex;
  flex-wrap: wrap;
}

Bootstrap same height flexbox example

To only apply the same height flexbox at specific breakpoints (responsive), use a media query. For example, here is sm (768px) and up:

@media (min-width: 768px) {
  .row.equal {
    display: flex;
    flex-wrap: wrap;
  }
}

This solution also works well for multiple rows (column wrapping): https://www.codeply.com/go/bp/gCEXzPMehZ

Other workarounds

These options will be recommended by others, but are not a good idea for responsive design. These only work for simple single row layouts w/o column wrapping.

  1. Using huge negative margins & padding

  2. Using display:table-cell (this solution also affects the responsive grid, so a @media query can be used to only apply table display on wider screens before the columns stack vertically)

tagurit
  • 494
  • 5
  • 13
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
86

No JavaScript needed. Just add the class .row-eq-height to your existing .row just like this:

<div class="row row-eq-height">
  <div class="col-xs-12 col-sm-4 panel" style="background-color: red">
    some content
  </div>
  <div class="col-xs-6 col-sm-4 panel" style="background-color: yellow">
    kittenz
  <img src="http://placekitten.com/100/100">
  </div>
  <div class="col-xs-6 col-sm-4 panel" style="background-color: blue">
    some more content
  </div>
</div>

Tip: if you have more than 12 columns in your row, the bootstrap grid will fail to wrap it. So add a new div.row.row-eq-height each 12 columns.

Tip: you may need to add

<link rel="stylesheet" href="http://getbootstrap.com.vn/examples/equal-height-columns/equal-height-columns.css" />

to your html

benomatis
  • 5,536
  • 7
  • 36
  • 59
Kevin R.
  • 1,283
  • 10
  • 8
70

To answer your question this is all you need see full responsive demo with prefixed css:

/* Using col-xs media query breakpoint but you can change 481 to 768 to only apply to col-sm and above if you'd like*/

@media only screen and (min-width : 481px) {
    .flex-row {
        display: flex;
        flex-wrap: wrap;
    }
    .flex-row > [class*='col-'] {
        display: flex;
        flex-direction: column;
    }
    .flex-row.row:after, 
    .flex-row.row:before {
        display: flex;
    }
}

Screenshot of Codepen

To add support for thumbnail content flex within flex columns like the screenshot above also add this... Note you could do this with panels as well:

.flex-row .thumbnail,
.flex-row .caption {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
}
.flex-text {
    flex-grow: 1;
}    
.flex-row img {
    width: 100%;
}

While flexbox doesn't work in IE9 and below you can use the demo with a fallback using conditional tags with something like javascript grids as a polyfill:

<!--[if lte IE 9]>

<![endif]-->

As for the other two examples in the accepted answer... The table demo is a decent idea but is being implemented wrong. Applying that CSS on bootstrap column classes specifically will without a doubt break the grid framework entirely. You should be using a custom selector for one and two the tables styles should not be applied to [class*='col-'] that have defined widths. This method should ONLY be used if you want equal height AND equal width columns. It is not meant for any other layouts and is NOT responsive. We can make it fallback however on mobile displays...

<div class="table-row-equal">
<div class="thumbnail">
    Content...
</div>
<div class="thumbnail">
    Content...
</div>
</div>
@media only screen and (min-width : 480px){
    .table-row-equal {
        display: table;
        width: 100%;
        table-layout: fixed;
        border-spacing: 30px 0px;
        word-wrap: break-word;
    }
    .table-row-equal .thumbnail {
        float: none;
        display: table-cell;
        vertical-align: top;
        width: 1%;
    }
}

Lastly, the first demo in the accepted answer which implements a version of the one true layout is a good choice for some situations, but not suitable for bootstrap columns. The reason for this is that all the columns expand to the container height. So this will also break responsiveness since the columns are not expanding to the elements next to them, but the entire container. This method will also not allow you to apply bottom margins to rows any longer and will also cause other issues along the way like scrolling to anchor tags.

For the complete code see the Codepen which automatically prefixes the flexbox code.

Edric
  • 24,639
  • 13
  • 81
  • 91
Bryan Willis
  • 3,552
  • 1
  • 25
  • 34
  • 12
    That is the only one answer that actually worked for me. The 3 top rated answers were just a waste of time – ken2k Apr 07 '16 at 08:42
  • Glad somebody found it useful. I definitely wasted way too much time creating that demo! One thing to note when using this and flexbox in general is that not all browsers are created equal. It is a pretty new concept and there are some quirks with it still depending on your layouts, so just make sure you do some cross browser testing before using it live. – Bryan Willis Apr 08 '16 at 06:46
  • Also if you do run into any issues with my method in the demo, I'd love to hear about it so I can make sure to fix it or add your example. – Bryan Willis Apr 08 '16 at 06:48
  • @bwillis Had to edit the masonry example to use `.masonary-row > [class*="col-"] ` to not break inner cols and added a breakpoint at 992px to have another column, but apart from that the Masonry works like a charm, kudos! – Marcelo Apr 21 '16 at 02:22
  • Yes this is the only answer here that works and is responsive. Make this the accepted answer. – Matthew Lock May 18 '16 at 04:46
  • 3
    Looks good, but unfortunately it doesn't work in Safari 9.1 on MacOS :-( – KevinH May 24 '16 at 12:22
  • Thanks for the heads up @TheSchecke I will check it out today and update. – Bryan Willis May 27 '16 at 15:10
  • 1
    @TheSchecke here is the fix. As far as I know this works in all flexbox supported browsers now. Please let me know if I'm wrong. http://s.codepen.io/bootstrapped/debug/pboJNd. The problem had to do with the `row:after, row:before` having display: table set which apparently Safari doesn't like. – Bryan Willis May 27 '16 at 15:56
  • 2
    Just a heads up that this breaks really badly on the iPad's Safari browser – Matthew Lock Jul 08 '16 at 00:31
  • 1
    Sorry to hear that @MatthewLock. I just tested on my IPad Air IOS 8.1 with latest safari and it works on that. I was also able to test on on crossbrowsertesting.com using iPad mini retina with Safari 7 and that seems to be working fine too. [Here's the results](https://app.crossbrowsertesting.com/public/ic0b282d4f9e833b/screenshots/z8266ad2bb0f78ea5d4a/zd10b4bbdee1604c1c52) of that test. Can you provide the iPad and Safari version you are using? I'd love to try to get this fixed asap or at least put a comment in the answer as I know a lot of people are using it. – Bryan Willis Jul 08 '16 at 05:09
  • Thanks Bryan. I will check that out. – Matthew Lock Jul 09 '16 at 01:46
  • @Jordan.J.D which link? They don't seem to be expired as far as I can tell. – Bryan Willis Oct 11 '17 at 05:49
  • Safary issue fixed with a help of ::before and ::after pseudo!) Thanks a lot man!) – YUzhva Aug 17 '18 at 10:20
  • Came back for the same question more than two years later, not disappointed I commented/voted for this answer the first time, still perfectly fine and problem fixed within a few minutes! – ken2k Nov 22 '18 at 16:35
  • This answer is da bom! The only one that worked for me consistently, and on iPad Safari (iOS 12). – Jay Mar 21 '19 at 14:34
44

You only show one row so your use case may be limited to just that. Just in case you have multiple rows, this plugin - github Javascript-grids - works perfectly! It makes each panel expand to the tallest panel, giving each row potentially a different height based on the tallest panel in that row. It's a jquery solution vs. css, but wanted to recommend it as an alternative approach.

Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
globalSchmidt
  • 1,329
  • 16
  • 28
  • 1
    The only solution that really works and it doesn't break responsiveness – Artur Kedzior Oct 27 '16 at 21:21
  • Does this allow you to specify that the columns should be square - or just all the same height? – niico Nov 03 '16 at 23:26
  • @niico 14 - its been awhile since I've used this, but in my application the requirement is that the elements in each row were the same height, but the height might vary from row to row. Since the height is a function of the elements in the row, if your element height is equal to their width, then they should present as squares. – globalSchmidt Nov 04 '16 at 13:46
33

If you want to make this work in any browser, use javascript:

$( document ).ready(function() {
    var heights = $(".panel").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $(".panel").height(maxHeight);
});
paulalexandru
  • 9,218
  • 7
  • 66
  • 94
  • 1
    Have one div class="row" with variable number of panels each of class "col-md-4" which should give me 3 columns and unknown number of rows, depending on number of items I want to list. This JS worked and requires minimal change in my HTML/CSS, as opposed to various CSS thingies I tried. Only thing I changed was to mark all my column panels with additional class, i.e. "same-height-panel" and then use $(".same-height-panel") instead of $(".panel") – nidalpres Jun 18 '15 at 15:35
  • 1
    The only solution that worked for me after one day of experimenting with css stuff. – Dinosaurius Feb 03 '17 at 21:45
  • 1
    This is a good solution, but `.ready()` is not the right time to call it - it should be called on `.load()` – jave.web Jul 25 '17 at 13:07
  • 1
    @jave.web If you think that this is a good solution, please give it a thumbs up. Thanks – paulalexandru Jul 25 '17 at 13:38
  • Use `window.onload = function() {...function content above...}` instead. This works better. – Blackpanther0001 Feb 20 '18 at 22:23
  • +1 Just like many others have said, the above solution seems to be a cleaner approach which does not temper with the css file. – Phemelo Khetho Feb 24 '21 at 08:58
21

I tried alot of the suggestions made in this thread and on other pages but no solution worked 100% in every browsers.

So I experimented quite some time and came up with this. A complete solution for Bootstrap Equal Height columns with the help of flexbox with only 1 class. This works in all major browsers IE10+.

CSS:

.row.equal-cols {
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.row.equal-cols:before,
.row.equal-cols:after {
  display: block;
}

.row.equal-cols > [class*='col-'] {
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

.row.equal-cols > [class*='col-'] > * {
  -webkit-flex: 1 1 auto;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto; 
}

HTML:

<div class="container">
  <div class="row equal-cols">
    <div class="col-sm-4">
      <div class="content"></div>
    </div>
    <div class="col-sm-4">
      <div class="content"></div>
    </div>
    <div class="col-sm-4">
      <div class="content"></div>
    </div>
  </div>
</div>

To support even more versions of IE you can, for example, use https://github.com/liabru/jquery-match-height and target all child columns of .equal-cols. Like this:

// Create a check for IE9 (or any other specific browser).
if(IE9) {
  $(".row.equal-cols > [class*='col-']").matchHeight();
}

Without this polyfill the columns will behave as usual Bootstrap columns so which is a quite good fallback.

Adam Lindqvist
  • 211
  • 2
  • 3
16

From official documentation. Maybe you can use it in your case.

When you need equal height, add .h-100 to the cards.

<div class="row row-cols-1 row-cols-md-3 g-4">
  <div class="col">
   <div class="card h-100">
     <div>.....</div>
  </div>
  <div class="col">
   <div class="card h-100">
     <div>.....</div>
  </div>
Ramazan
  • 273
  • 3
  • 7
10

I'm surprised I couldn't find a worthwhile solution here late 2018. I went ahead and figured it out a Bootstrap 3 solution myself using flexbox.

Clean and simple example:

Example of matched column widths in Bootstrap 3

HTML

<div class="row row-equal">
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 col-equal">
        <p>Text</p>
    </div>
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 col-equal">
        <img src="//placehold.it/200x200">
    </div>
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 col-equal">
        <p>Text</p>
    </div>  
</div>

CSS

img {
  width: 100%;
}
p {
  padding: 2em;
}
@media (min-width: 768px) {
  .row-equal {
    display: flex;
    flex-wrap: wrap;
  }
  .col-equal {
    margin: auto;
  }
}

View working demo: http://jsfiddle.net/5kmtfrny/

BuffMcBigHuge
  • 579
  • 5
  • 8
9

You can use inline-flex as well which works pretty good and may be a little cleaner than modifying every row element with CSS.

For my project I wanted every row who's child elements had borders to be the same height so the borders would look jagged. For this I created a simple css class.

.row.borders{
    display: inline-flex;
    width: 100%;
}
Steffan Perry
  • 2,112
  • 1
  • 21
  • 21
  • 2
    While it succeeds at making all the contents in the row the same height; This breaks the responsiveness of Bootstrap. – Christine268 Jun 04 '15 at 01:29
9
.row-eq-height {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display:         flex;
 }

From:

http://getbootstrap.com.vn/examples/equal-height-columns/equal-height-columns.css

eaglei22
  • 2,589
  • 1
  • 38
  • 53
8

If anyone using bootstrap 4 and looking for equal height columns just use row-eq-height to parent div

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row row-eq-height">
  <div class="col-xs-4" style="border: 1px solid grey;">.row.row-eq-height &gt; .col-xs-4</div>
  <div class="col-xs-4" style="border: 1px solid grey;">.row.row-eq-height &gt; .col-xs-4<br>this is<br>a much<br>taller<br>column<br>than the others</div>
  <div class="col-xs-4" style="border: 1px solid grey;">.row.row-eq-height &gt; .col-xs-4</div>
</div>

Ref: http://getbootstrap.com.vn/examples/equal-height-columns/

brooksrelyt
  • 3,925
  • 5
  • 31
  • 54
Znaneswar
  • 3,329
  • 2
  • 16
  • 24
7

cheeky jquery solution if anyone's interested. Just make sure all your cols (el) have a common classname...works responsively too if you bind it to $(window).resize

function equal_cols(el)
{
    var h = 0;
    $(el).each(function(){
        $(this).css({'height':'auto'});
        if($(this).outerHeight() > h)
        {
            h = $(this).outerHeight();
        }
    });
    $(el).each(function(){
        $(this).css({'height':h});
    });
}

Usage

$(document).ready(function(){
   equal_cols('.selector');
});

Note: This post has been edited as per @Chris' comment out that the code was only set the last highest height in the $.each() function

Chay22
  • 2,834
  • 2
  • 17
  • 25
Marty
  • 79
  • 1
  • 1
  • This is understated - simple and small yet will resize all columns without needing to have a fixed number of columns in a row. Nice one! – Jordon Jan 17 '15 at 03:36
  • 1
    This isn't working, cause you set the last biggest height in the each function. If the third column is the highest column, column 1 and 2 aren't getting the right height.. You have to set the last line "$(this).css({'height':h});" after the each function. I will do an edit. – Chris Feb 05 '15 at 11:06
7

Some of the previous answers explain how to make the divs the same height, but the problem is that when the width is too narrow the divs won't stack, therefore you can implement their answers with one extra part. For each one you can use the CSS name given here in addition to the row class that you use, so the div should look like this if you always want the divs to be next to each other:

<div class="row row-eq-height-xs">Your Content Here</div>

For all screens:

.row-eq-height-xs {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display:         flex;
    flex-direction: row;
}

For when you want to use sm:

.row-eq-height-sm {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display:         flex;
    flex-direction: column;
}
@media (min-width:768px) {
    .row-eq-height-sm {
        flex-direction: row;
    }
}

For when you want to md:

.row-eq-height-md {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display:         flex;
    flex-direction: column;
}
@media (min-width:992px) {
    .row-eq-height-md {
        flex-direction: row;
    }
}

For when you want to use lg:

.row-eq-height-lg {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display:         flex;
    flex-direction: column;
}
@media (min-width:1200px) {
    .row-eq-height-md {
        flex-direction: row;
    }
}

EDIT Based on a comment, there is indeed a simpler solution, but you need to make sure to give column info from the largest desired width for all sizes down to xs (e.g. <div class="col-md-3 col-sm-4 col-xs-12">:

.row-eq-height {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
}
Zachary Weixelbaum
  • 904
  • 1
  • 11
  • 24
5

I know I'm very late but now you can use the "min-height" style attribute to achieve your purpose.

Faiz
  • 543
  • 1
  • 7
  • 10
5

So yes, Bootstrap 4 does make all the cols in a row equal height, however if you are creating a border around the content inside the row you may find that it appears like the cols are not equal heights!

When I applied height: 100% to the element inside the col I found that I lost my margin.

My solution is to use padding on the col's div (instead of a margin on the inner element). Like so:

<div class="container">
    <div class="row">
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-12 py-4">
            <div class="h-100 border round">
                        ...
            </div>
        </div>
    </div>
</div>

The above code example uses Bootstrap 4.1 to create a set of nine boxes with a border

Dagmar
  • 2,968
  • 23
  • 27
4
.row.container-height {
    overflow: hidden;
}

.row.container-height>[class*="col-"] {
    margin-bottom: -99999px;
    padding-bottom: 99999px;
}

where .container-height is the style class that has to be added to a .row styled element to which all its .col* children have the same height.

Applying these styles only to some specific .row (with .container-height, as in the example) also avoids applying the margin and padding overflow to all .col*.

DarkScrolls
  • 581
  • 5
  • 10
4

Best out there:

Reflex - Docs

Works with Bootstrap

Update:

  1. Include the CSS
  2. Update your code:

/*!
 *
 * Reflex v1.0
 *
 * Reflex is a flexbox grid which provides a way to take advantage of emerging
 * flexbox support while providing a fall back to inline-block on older browsers
 *
 * Built by Lee Jordan G.C.S.E.
 * email: ldjordan@gmail.com
 * github: https://github.com/leejordan
 *
 * Structure and calculations are inspired by twitter bootstrap
 *
 */

.reflex-order-12 {
  -webkit-order: 12;
  -ms-flex-order: 12;
  order: 12;
}

.reflex-order-11 {
  -webkit-order: 11;
  -ms-flex-order: 11;
  order: 11;
}

.reflex-order-10 {
  -webkit-order: 10;
  -ms-flex-order: 10;
  order: 10;
}

.reflex-order-9 {
  -webkit-order: 9;
  -ms-flex-order: 9;
  order: 9;
}

.reflex-order-8 {
  -webkit-order: 8;
  -ms-flex-order: 8;
  order: 8;
}

.reflex-order-7 {
  -webkit-order: 7;
  -ms-flex-order: 7;
  order: 7;
}

.reflex-order-6 {
  -webkit-order: 6;
  -ms-flex-order: 6;
  order: 6;
}

.reflex-order-5 {
  -webkit-order: 5;
  -ms-flex-order: 5;
  order: 5;
}

.reflex-order-4 {
  -webkit-order: 4;
  -ms-flex-order: 4;
  order: 4;
}

.reflex-order-3 {
  -webkit-order: 3;
  -ms-flex-order: 3;
  order: 3;
}

.reflex-order-2 {
  -webkit-order: 2;
  -ms-flex-order: 2;
  order: 2;
}

.reflex-order-1 {
  -webkit-order: 1;
  -ms-flex-order: 1;
  order: 1;
}

.reflex-order-0 {
  -webkit-order: 0;
  -ms-flex-order: 0;
  order: 0;
}

.reflex-container {
  display: inline-block;
  display: -webkit-flex;
  display: flex;
  zoom: 1;
  *display: inline;
  margin: 0;
  padding: 0;
  position: relative;
  width: 100%;
  letter-spacing: -0.31em;
  *letter-spacing: normal;
  word-spacing: -0.43em;
  list-style-type: none;
}

.reflex-container *,
.reflex-container:before,
.reflex-container:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  max-width: 100%;
  letter-spacing: normal;
  word-spacing: normal;
  white-space: normal;
}

.reflex-container *:before,
.reflex-container *:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

[class*="reflex-col-"] {
  width: 100%;
  vertical-align: top;
  position: relative;
  display: inline-block;
  display: -webkit-flex;
  display: flex;
  zoom: 1;
  *display: inline;
  text-align: left;
  text-align: start;
}

.reflex-item {
  display: block;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
}

_:-ms-fullscreen,
:root .reflex-item {
  width: 100%;
}

.reflex-col-12 {
  width: 100%;
  *width: 99.9%;
}

.reflex-col-11 {
  width: 91.66666666666666%;
  *width: 91.56666666666666%;
}

.reflex-col-10 {
  width: 83.33333333333334%;
  *width: 83.23333333333335%;
}

.reflex-col-9 {
  width: 75%;
  *width: 74.9%;
}

.reflex-col-8 {
  width: 66.66666666666666%;
  *width: 66.56666666666666%;
}

.reflex-col-7 {
  width: 58.333333333333336%;
  *width: 58.233333333333334%;
}

.reflex-col-6 {
  width: 50%;
  *width: 49.9%;
}

.reflex-col-5 {
  width: 41.66666666666667%;
  *width: 41.56666666666667%;
}

.reflex-col-4 {
  width: 33.33333333333333%;
  *width: 33.23333333333333%;
}

.reflex-col-3 {
  width: 25%;
  *width: 24.9%;
}

.reflex-col-2 {
  width: 16.666666666666664%;
  *width: 16.566666666666663%;
}

.reflex-col-1 {
  width: 8.333333333333332%;
  *width: 8.233333333333333%;
}

@media (min-width: 480px) {
  .reflex-col-xs-12 {
    width: 100%;
    *width: 99.9%;
  }
  .reflex-col-xs-11 {
    width: 91.66666666666666%;
    *width: 91.56666666666666%;
  }
  .reflex-col-xs-10 {
    width: 83.33333333333334%;
    *width: 83.23333333333335%;
  }
  .reflex-col-xs-9 {
    width: 75%;
    *width: 74.9%;
  }
  .reflex-col-xs-8 {
    width: 66.66666666666666%;
    *width: 66.56666666666666%;
  }
  .reflex-col-xs-7 {
    width: 58.333333333333336%;
    *width: 58.233333333333334%;
  }
  .reflex-col-xs-6 {
    width: 50%;
    *width: 49.9%;
  }
  .reflex-col-xs-5 {
    width: 41.66666666666667%;
    *width: 41.56666666666667%;
  }
  .reflex-col-xs-4 {
    width: 33.33333333333333%;
    *width: 33.23333333333333%;
  }
  .reflex-col-xs-3 {
    width: 25%;
    *width: 24.9%;
  }
  .reflex-col-xs-2 {
    width: 16.666666666666664%;
    *width: 16.566666666666663%;
  }
  .reflex-col-xs-1 {
    width: 8.333333333333332%;
    *width: 8.233333333333333%;
  }
}

@media (min-width: 768px) {
  .reflex-col-sm-12 {
    width: 100%;
    *width: 99.9%;
  }
  .reflex-col-sm-11 {
    width: 91.66666666666666%;
    *width: 91.56666666666666%;
  }
  .reflex-col-sm-10 {
    width: 83.33333333333334%;
    *width: 83.23333333333335%;
  }
  .reflex-col-sm-9 {
    width: 75%;
    *width: 74.9%;
  }
  .reflex-col-sm-8 {
    width: 66.66666666666666%;
    *width: 66.56666666666666%;
  }
  .reflex-col-sm-7 {
    width: 58.333333333333336%;
    *width: 58.233333333333334%;
  }
  .reflex-col-sm-6 {
    width: 50%;
    *width: 49.9%;
  }
  .reflex-col-sm-5 {
    width: 41.66666666666667%;
    *width: 41.56666666666667%;
  }
  .reflex-col-sm-4 {
    width: 33.33333333333333%;
    *width: 33.23333333333333%;
  }
  .reflex-col-sm-3 {
    width: 25%;
    *width: 24.9%;
  }
  .reflex-col-sm-2 {
    width: 16.666666666666664%;
    *width: 16.566666666666663%;
  }
  .reflex-col-sm-1 {
    width: 8.333333333333332%;
    *width: 8.233333333333333%;
  }
}

@media (min-width: 992px) {
  .reflex-col-md-12 {
    width: 100%;
    *width: 99.9%;
  }
  .reflex-col-md-11 {
    width: 91.66666666666666%;
    *width: 91.56666666666666%;
  }
  .reflex-col-md-10 {
    width: 83.33333333333334%;
    *width: 83.23333333333335%;
  }
  .reflex-col-md-9 {
    width: 75%;
    *width: 74.9%;
  }
  .reflex-col-md-8 {
    width: 66.66666666666666%;
    *width: 66.56666666666666%;
  }
  .reflex-col-md-7 {
    width: 58.333333333333336%;
    *width: 58.233333333333334%;
  }
  .reflex-col-md-6 {
    width: 50%;
    *width: 49.9%;
  }
  .reflex-col-md-5 {
    width: 41.66666666666667%;
    *width: 41.56666666666667%;
  }
  .reflex-col-md-4 {
    width: 33.33333333333333%;
    *width: 33.23333333333333%;
  }
  .reflex-col-md-3 {
    width: 25%;
    *width: 24.9%;
  }
  .reflex-col-md-2 {
    width: 16.666666666666664%;
    *width: 16.566666666666663%;
  }
  .reflex-col-md-1 {
    width: 8.333333333333332%;
    *width: 8.233333333333333%;
  }
}

@media (min-width: 1200px) {
  .reflex-col-lg-12 {
    width: 100%;
    *width: 99.9%;
  }
  .reflex-col-lg-11 {
    width: 91.66666666666666%;
    *width: 91.56666666666666%;
  }
  .reflex-col-lg-10 {
    width: 83.33333333333334%;
    *width: 83.23333333333335%;
  }
  .reflex-col-lg-9 {
    width: 75%;
    *width: 74.9%;
  }
  .reflex-col-lg-8 {
    width: 66.66666666666666%;
    *width: 66.56666666666666%;
  }
  .reflex-col-lg-7 {
    width: 58.333333333333336%;
    *width: 58.233333333333334%;
  }
  .reflex-col-lg-6 {
    width: 50%;
    *width: 49.9%;
  }
  .reflex-col-lg-5 {
    width: 41.66666666666667%;
    *width: 41.56666666666667%;
  }
  .reflex-col-lg-4 {
    width: 33.33333333333333%;
    *width: 33.23333333333333%;
  }
  .reflex-col-lg-3 {
    width: 25%;
    *width: 24.9%;
  }
  .reflex-col-lg-2 {
    width: 16.666666666666664%;
    *width: 16.566666666666663%;
  }
  .reflex-col-lg-1 {
    width: 8.333333333333332%;
    *width: 8.233333333333333%;
  }
}

.reflex-wrap {
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.reflex-wrap-reverse {
  -webkit-flex-wrap: wrap-reverse;
  flex-wrap: wrap-reverse;
}

.reflex-direction-row-reverse {
  -webkit-flex-direction: row-reverse;
  flex-direction: row-reverse;
}

.reflex-direction-column {
  -webkit-flex-direction: column;
  flex-direction: column;
}

.reflex-direction-column-reverse {
  -webkit-flex-direction: column-reverse;
  flex-direction: column-reverse;
}

.reflex-align-start {
  -webkit-align-items: flex-start;
  align-items: flex-start;
}

.reflex-align-end {
  -webkit-align-items: flex-end;
  align-items: flex-end;
}

.reflex-align-end [class*="reflex-col-"] {
  vertical-align: bottom;
}

.reflex-align-center {
  -webkit-align-items: center;
  align-items: center;
}

.reflex-align-center [class*="reflex-col-"] {
  vertical-align: middle;
}

.reflex-align-baseline {
  -webkit-align-items: baseline;
  align-items: baseline;
}

.reflex-align-baseline [class*="reflex-col-"] {
  vertical-align: baseline;
}

.reflex-align-content-start {
  -webkit-align-content: flex-start;
  align-content: flex-start;
}

.reflex-align-content-end {
  -webkit-align-content: flex-end;
  align-content: flex-end;
}

.reflex-align-content-end [class*="reflex-col-"] {
  vertical-align: bottom;
}

.reflex-align-content-center {
  -webkit-align-content: center;
  align-content: center;
}

.reflex-align-content-space-between {
  -webkit-align-content: space-between;
  align-content: space-between;
}

.reflex-align-content-space-around {
  -webkit-align-content: space-around;
  align-content: space-around;
}

.reflex-align-self-stretch {
  -webkit-align-self: stretch;
  align-self: stretch;
}

.reflex-align-self-start {
  -webkit-align-self: flex-start;
  align-self: flex-start;
}

.reflex-align-self-end {
  -webkit-align-self: flex-end;
  align-self: flex-end;
  vertical-align: bottom;
}

.reflex-align-self-center {
  -webkit-align-self: center;
  align-self: center;
  vertical-align: middle;
}

.reflex-align-self-baseline {
  -webkit-align-self: baseline;
  align-self: baseline;
  vertical-align: baseline;
}

.reflex-justify-start {
  text-align: left;
  -webkit-justify-content: flex-start;
  justify-content: flex-start;
}

.reflex-justify-end {
  text-align: right;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
}

.reflex-justify-center {
  text-align: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.reflex-justify-space-between {
  text-align: justify;
  -moz-text-align-last: justify;
  text-align-last: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
}

.reflex-justify-space-around {
  text-align: justify;
  -moz-text-align-last: justify;
  text-align-last: justify;
  -webkit-justify-content: space-around;
  justify-content: space-around;
}

.reflex-item-margin-sm {
  margin: 0 0.25em 0.5em;
}

.reflex-item-margin-md {
  margin: 0 0.5em 1em;
}

.reflex-item-margin-lg {
  margin: 0 1em 2em;
}

.reflex-item-content-margin-sm * {
  margin-right: 0.25em;
  margin-left: 0.25em;
}

.reflex-item-content-margin-md * {
  margin-right: 0.5em;
  margin-left: 0.25em;
}

.reflex-item-content-margin-lg * {
  margin-right: 1em;
  margin-left: 1em;
}

.reflex-img {
  display: inline-block;
  display: -webkit-flex;
  display: flex;
  zoom: 1;
  *display: inline;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  margin-left: 0;
  margin-right: 0;
  max-width: 100%;
  width: 100%;
  height: auto;
}

.reflex-item-footer {
  margin-top: auto;
  margin-left: 0;
  margin-right: 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

<div class="reflex-container reflex-wrap">
  <div class="reflex-col-xs-12 reflex-col-sm-4 panel" style="background-color: red">
    some content
  </div>
  <div class="reflex-col-xs-6 reflex-col-sm-4 panel" style="background-color: yellow">
    kittenz
    <img src="https://upload.wikimedia.org/wikipedia/en/1/13/Matrona.jpg">
  </div>
  <div class="reflex-col-xs-6 reflex-col-sm-4 panel" style="background-color: blue">
    some more content
  </div>
</div>
tagurit
  • 494
  • 5
  • 13
Bernd Loigge
  • 1,647
  • 1
  • 14
  • 17
  • Welcome to Stack Overflow! While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. See [How do I write a good answer](http://stackoverflow.com/help/how-to-answer). – ByteHamster May 04 '15 at 15:57
3

here is my solution (compiled CSS):

.row.row-xs-eq {
  display: table;
  table-layout: fixed;
  margin: 0;
}

.row.row-xs-eq::before {
  content: none;
}

.row.row-xs-eq::after {
  content: none;
}

.row.row-xs-eq > [class^='col-'] {
  display: table-cell;
  float: none;
  padding: 0;
}

@media (min-width: 768px) {
  .row.row-sm-eq {
    display: table;
    table-layout: fixed;
    margin: 0;
  }

  .row.row-sm-eq::before {
    content: none;
  }

  .row.row-sm-eq::after {
    content: none;
  }

  .row.row-sm-eq > [class^='col-'] {
    display: table-cell;
    float: none;
    padding: 0;
  }
}

@media (min-width: 992px) {
  .row.row-md-eq {
    display: table;
    table-layout: fixed;
    margin: 0;
  }

  .row.row-md-eq::before {
    content: none;
  }

  .row.row-md-eq::after {
    content: none;
  }

  .row.row-md-eq > [class^='col-'] {
    display: table-cell;
    float: none;
    padding: 0;
  }
}

@media (min-width: 1200px) {
  .row.row-lg-eq {
    display: table;
    table-layout: fixed;
    margin: 0;
  }

  .row.row-lg-eq::before {
    content: none;
  }

  .row.row-lg-eq::after {
    content: none;
  }

  .row.row-lg-eq > [class^='col-'] {
    display: table-cell;
    float: none;
    padding: 0;
  }
}

So your code would look like:

<div class="row row-sm-eq">
  <!-- your old cols definition here -->
</div>

Basically this is the same system you use with .col-* classes with that difference you need to apply .row-* classes to the row itself.

With .row-sm-eq columns will be stacked on XS screens. If you don't need them to be stacked on any screens you can use .row-xs-eq.

The SASS version that we do actually use:

.row {
  @mixin row-eq-height {
    display: table;
    table-layout: fixed;
    margin: 0;

    &::before {
      content: none;
    }

    &::after {
      content: none;
    }

    > [class^='col-'] {
      display: table-cell;
      float: none;
      padding: 0;
    }
  }

  &.row-xs-eq {
    @include row-eq-height;
  }

  @media (min-width: $screen-sm-min) {
    &.row-sm-eq {
      @include row-eq-height;
    }
  }

  @media (min-width: $screen-md-min) {
    &.row-md-eq {
      @include row-eq-height;
    }
  }

  @media (min-width: $screen-lg-min) {
    &.row-lg-eq {
      @include row-eq-height;
    }
  }
}

Live demo


Note: mixing .col-xs-12 and .col-xs-6 inside a single row would not work properly.

R3tep
  • 12,512
  • 10
  • 48
  • 75
Alexander S.
  • 267
  • 3
  • 11
  • This is good. My solution is the same. And there is a possibility to have equal height columns with standard Bootstrap's 30px gaps between columns using `border-spacing` and negative margins. – max Dec 08 '17 at 16:43
3

There is a problem with using Solution 1 while appling it on only column in rows. Would like to improve Solution 1.

 [class^="col-"]:not([class*="-12"]){
      margin-bottom: -99999px;
      padding-bottom: 99999px;
  }

(Sorry, can't comment Popnoodles's anwer. I have not enough reputations)

S. Ponomarev
  • 43
  • 1
  • 9
3

For those looking for a quick, easy solution - if you have a relatively consistent set of block content setting a min-height on the div that is a bit bigger than the largest block can be easier to implement.

.align-box {
    min-height: 400px;
}
Neal
  • 3,102
  • 1
  • 14
  • 16
3

03/19/2019

**Bootstrap 4 Equal Height Solution **

Bootstrap Utilities/flex for equal height

Live example in Codepen

Equal height by bootstrap class with parent div fixed height or min-height

<div class="d-flex align-content-stretch flex-wrap" style="min-height: 200px">
    <div>Flex height test text for example , Flex height test text for example </div>
    <div>Flex item</div>
    <div>Flex item</div>
    <div>Flex item</div>
 </div>

.bd-highlight {
    background-color: rgba(86,61,124,.15);
    border: 1px solid rgba(86,61,124,.15);
}
.fixed-height-200 {
  min-height: 200px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<br><br><br>
<div class="d-flex align-content-stretch flex-wrap fixed-height-200">
    <div class="p-2 bd-highlight">Flex item <br> 1111111111</div>
    <div class="p-2 bd-highlight bg-danger">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight bg-info">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight bg-light">Flex item <br> 1111111111</div>
    <div class="p-2 bd-highlight">Flex item <br> 1111111111</div>
    <div class="p-2 bd-highlight">Flex item <br> 1111111111</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight bg-primary">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
    <div class="p-2 bd-highlight">Flex item</div>
</div>
MD Ashik
  • 9,117
  • 10
  • 52
  • 59
2

Here is my method, i have used flex with some changes in media query.

  @media (min-width: 0px) and (max-width: 767px) {
  .fsi-row-xs-level {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .fsi-row-sm-level {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .fsi-row-md-level {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }
}
@media (min-width: 1200px) {
  .fsi-row-lg-level {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }
}

then added the classes to the parent which were required.

<div class="row fsi-row-lg-level fsi-row-md-level">
<div class="col-sm-4">column 1</div>
<div class="col-sm-4">column 2</div>
<div class="col-sm-4">column 3</div>
</div>

I am using responsive breakpoints because flux usually hampers the bootstrap standard responsive nature.

2

I use this super easy solution with clearfix, which doesn't have any side effects.

Here is an example on AngularJS:

<div ng-repeat-start="item in list">
    <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12"></div>
</div>
<div ng-repeat-end>
    <div ng-if="$index % 3 == 2" class="clearfix visible-lg"></div>
    <div ng-if="$index % 2 == 1" class="clearfix visible-md"></div>
</div>

And one more example on PHP:

<?php foreach ($list as $i => $item): ?>
    <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12"></div>
    <div class="clearfix visible-md"></div>
    <?php if ($i % 2 === 1): ?>
        <div class="clearfix visible-lg"></div>
    <?php endif; ?>
<?php endforeach; ?>
Oleg
  • 7,070
  • 4
  • 47
  • 49
2

I searched for a solution to the same problem, and found one just worked !! - with almost no extra code..

see https://medium.com/wdstack/bootstrap-equal-height-columns-d07bc934eb27 for a good disuccuion, and with the resposne you want in the bottom, with a link.

https://www.codeply.com/go/EskIjvun4B

this was the correct responsive way to for me... a quote: ... 3 — Use flexbox (best!)

As of 2017, the best (and easiest) way to make equal height columns in a responsive design is using CSS3 flexbox.

.row.display-flex {
  display: flex;
  flex-wrap: wrap;
}
.row.display-flex > [class*='col-'] {
  display: flex;
  flex-direction: column;
}

and simply use:

div class="container">
   <div class="row display-flex .... etc..
kfn
  • 620
  • 1
  • 7
  • 26
1

If it makes sense in your context, you can simply add an empty 12-column div after each break, which acts as a divider that hugs the bottom of the tallest cell in your row.

<div class="row">
   <div class="col-xs-6">Some content</div>
   <div class="col-xs-6">
      Lots of content! Lots of content! Lots of content! Lots of content! Lots of content! 
   </div>
   <div id="spacer-div" class="col-xs-12"></div>
   <div class="col-xs-6">More content...</div>
</div><!--this You forgot to close -->

Hope this helps!

VishAl
  • 388
  • 3
  • 17
Chris Staikos
  • 1,150
  • 10
  • 24
1
@media (min-width: @screen-sm-min) {
    div.equal-height-sm {
        display: table;


        > div[class^='col-'] {
            display: table-cell;
            float: none;
            vertical-align: top;
        }
    }
}

<div class="equal-height-sm">
    <div class="col-xs-12 col-sm-7">Test<br/>Test<br/>Test</div>
    <div class="col-xs-12 col-sm-5">Test</div>
</div>

Example:

https://jsfiddle.net/b9chris/njcnex83/embedded/result/

Adapted from several answers here. The flexbox-based answers are the right way once IE8 and 9 are dead, and once Android 2.x is dead, but that is not true in 2015, and likely won't be in 2016. IE8 and 9 still make up 4-6% of usage depending on how you measure, and for many corporate users it's much worse. http://caniuse.com/#feat=flexbox

The display: table, display: table-cell trick is more backwards-compatible - and one great thing is the only serious compatibility issue is a Safari issue where it forces box-sizing: border-box, something already applied to your Bootstrap tags. http://caniuse.com/#feat=css-table

You can obviously add more classes that do similar things, like .equal-height-md. I tied these to divs for the small performance benefit in my constrained usage, but you could remove the tag to make it more generalized like the rest of Bootstrap.

Note that the jsfiddle here uses CSS, and so, things Less would otherwise provide are hard-coded in the linked example. For example @screen-sm-min has been replaced with what Less would insert - 768px.

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
1

HTML

<div class="container-fluid">
    <div class="row-fluid">
        <div class="span4 option2">
            <p>left column </p>
            <p>The first column has to be the longest The first column has to be the longes</p>
        </div>

        <div class="span4 option2">
            <p>middle column</p>
        </div>

        <div class="span4 option2">
            <p>right column </p>
            <p>right column </p>
            <p>right column </p>
            <p>right column </p>
            <p>right column </p>
        </div>
    </div>
</div>

CSS

.option2 { background: red; border: black 1px solid; color: white; }

JS

$('.option2').css({
    'height': $('.option2').height()
});
brooksrelyt
  • 3,925
  • 5
  • 31
  • 54
Pacific P. Regmi
  • 1,607
  • 19
  • 15
0

Thought I'd just add that the answer given by Dr.Flink can also be applied to a Bootstrap 3 form-horizontal block - which can be very handy if you want to use background colours for each cell. In order for this to work for bootstrap forms, you would need to wrap the form contents which just serves to replicate a table-like structure.

The example below also provides the CSS which demonstrates an additional media query allows Bootstrap 3 to simply takeover and do it's normal thing on the smaller screen(s). This also works in IE8+ .

Example:

<form class="form-horizontal" role="form">

  <div class="form-wrapper">
    <div class="form-group">
      <label class="col-xs-12 col-sm-2 control-label">My Label</label>
      <div class="col-xs-12 col-sm-10">
        Some content
      </div>
    </div>
  </div>

</form>
.form-wrapper {
  display: table;
}

.form-wrapper .form-group {
  display: table-row;
}

.form-wrapper .form-group .control-label {
  display: table-cell;
  float: none;
}

.form-wrapper .form-group label + div {
  display: table-cell;
  float: none;
}

@media (max-width: 768px) {
  .form-wrapper {
    display: inherit;
  }
  .form-wrapper .form-group {
    display: block;
  }
  .form-wrapper .form-group .control-label {
    display: inherit;
  }
  .form-wrapper .form-group label + div {
    display: inherit;
  }
}
Igor Ivancha
  • 3,413
  • 4
  • 30
  • 39
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
0

You can wrap the columns inside a div

<div class="row">
<div class="col-md-12>
  <div class="col-xs-12 col-sm-4 panel" style="background-color: red">
  some content
  </div>
  <div class="col-xs-6 col-sm-4 panel" style="background-color: yellow">
  kittenz
  <img src="http://placekitten.com/100/100">
  </div>
  <div class="col-xs-6 col-sm-4 panel" style="background-color: blue">
  some more content
  </div>
</div>
</div>
Tom Kur
  • 2,248
  • 1
  • 18
  • 28
0

Try this do through flex-box

.container {
 display: flex;
 padding-bottom: 50px;
}
.col {
 background: blue;
 padding: 30px;
}

.col.center {
 background: red;
 height: 100px;
 margin-bottom: -50px;
}
<div class="container">
  <div class="col">Left</div>
  <div class="col center">Center</div>
  <div class="col">Right</div>
</div>

Live JSFiddle - https://jsfiddle.net/grinmax_/spsn4fnq/

grinmax
  • 1,835
  • 1
  • 10
  • 13
-4

Just checking through bootstrap documentation and I found the simple solution for the problem of column same height.

Add the extra clearfix for only the required viewport

<div class="clearfix visible-xs-block"></div>

For example:

<div class="col-md-3 col-xs-6">This is a long text</div>
<div class="col-md-3 col-xs-6">This is short</div>
<div class="clearfix visible-xs-block">This is a long text</div>
<div class="col-md-3 col-xs-6">Short</div>
<div class="col-md-3 col-xs-6">Long Text</div>
<div class="clearfix visible-xs-block"></div>
<div class="col-md-3 col-xs-6">Longer text which will push down</div>
<div class="col-md-3 col-xs-6">Short</div>

Please refer to http://getbootstrap.com/css/#grid-responsive-resets

Eddy Goh
  • 256
  • 5
  • 11
-5

You can use below code

var heights = $(".row > div").map(function() {
    return $(this).height();
}).get(),
maxHeight = Math.max.apply(null, heights);
$(".row > div").height(maxHeight);
-7

alot of css here...

jQuery

$(document).ready(function() {

   // Get height of original column you want to match
   var box-height = $('.panel:nth-child(1)').outerHeight();

   // Output same height on particular element or element(s)
   $('.panel').height(box-height);

});

Really simple code no need to play with css, although all options above are perfectly usable.

Jsfiddle

Nelson
  • 38
  • 1
  • 9
  • 10
    Yeah, there's a lot of CSS here because the question is tagged css and not javascript. Don't post JS solutions to problems that can be solved with pure CSS. In 99% of cases, the performance is worse. – cimmanon Jul 07 '15 at 13:30