2

Consider this markup:

<div class="row">
 <div class="col-xs-4">
 <img src="somesource.png">
 </div>
 <div class="col-xs-6">
 <h1>Some text</h1>
 </div>
 <div class="col-xs-2">
 <span class="glyphicon glyphicon-chevron-right"></span>
 </div>
</div>

If the image is around 100px in height and the rest is less. How are you supposed to properly set them to equal height without setting a hard coded valued height property on all of them?

The columns should be able to have absolute positioned elements inside them and still be equal height as the rest of the columns.

I tried writing a script for this, however, no matter what I did the height of the columns never got the correct value. The script looks like this:

var highest = 0,
 columns = $('.row').find('> div[class*="col"]');
$.each(columns, function() {
 var height = $(this).height();
 if (height > highest) {
 highest = height;
 }
});
$.each(columns, function() {
 $(this).css('height', highest + 'px');
});

However, this script seems to pick the lowest height and then apply that height to all the .cols.

Why isn't this working the way it should be? And isn't there a better way than doing it like this?

If possible, is there a pure CSS way of obtaining this behavior? Preferably without using table-like CSS rules.

asked Jul 5, 2015 at 17:50

1 Answer 1

2

You can find the answer to that question in questions already answered in StackOverflow:

Twitter Bootstrap 3 - Panels of Equal Height in a Fluid Row

Or here:

How can I make Bootstrap columns all the same height?

answered Jul 5, 2015 at 18:07
Sign up to request clarification or add additional context in comments.

1 Comment

Ye I know but they're not really optimal, and none of them seem to deal with having images in the columns. The flex solution would seem the best, I found that having just display: -webkit-box; fixes the issue for chrome and safari but not IE and Firefox. As soon as I add display: flex; it breaks my images by squeezing them together. After looking over the solution I'd probably prefer a JS solution since none of the CSS ones seem to work properly. Which also brings me back to the original problem, why isn't my script working?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.