I have some Bootstrap 3 Grid columns with different heights:
<div class="row">
<div class="col-xs-4">Item 1</div>
<div class="col-xs-4">Item 2 <br/> additional line
</div>
<div class="col-xs-4">Item 3</div>
<div class="col-xs-6">Item 4 - This should be on a separate line</div>
</div>
Which looks like this:
I want to add an additional class (e.g. .row-aligned
) to .row
to achieve that all abreast "cols" have the same height.
Which should look like this:
Because I don't need to support old browsers I can use flexbox. My attempt is quiet easy and works in all browsers but not in Safari (version 9.1, Mac OSX 10.10):
.aligned-row {
display: flex;
flex-flow: row wrap;
}
I prepared a Demo here.
As I said, Safari cannot handle this flexbox style and the result looks like this:
(I found out that adding margin-left: -1px
seems to fix the issue, but it is not a good solution, because it will move everything 1 pixel left which can hide borders or something else.)
Do you have any idea how I can fix this bug in Safari? Or do I use flexbox wrong? Or is there a better solution without using flexbox?
By setting the row to display:table , and the colums to display:table-cell we do indeed get a row of same height columns.
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.
You just have to use class="row-eq-height" with your class="row" to get equal height columns for previous bootstrap versions.
The solution is to "remove" the display: table
which is set to .row::before
:
.aligned-row {
display: flex;
flex-flow: row wrap;
&::before {
display: block;
}
}
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With