2 columns of equal height – Twitter’s Bootstrap 2.0

2 columns of equal height – Twitter’s Bootstrap 2.0

Well, everybody knows that Twitter’s Bootstrap is a great tool and makes a lot of things easier for those who, like me, doesn’t know much about CSS yet. But, sometimes, it can be a problem too.
The thing is: I’m using a fixed 940px-wide, 12-column grid centered layout with two columns, and I wanted that both of the columns had the same height. The code right now is like this:


©

As you can see, there are divs with no content, like “myP”, “otherP” and “not”. They are filled through Javascript, and the amount of content stored in them may vary and, because of that, in many times a column (The “columns” here are represented by the div with the “div-content” class and by the div with the “div-sidebar” class) will be bigger than the other (In my particular case, both columns may be “the bigger one”).
Here’s a picture, if it helps:

Related:  How do you Bind to Angular-UI's Carousel Slide Events?

Basically, the left column (The

in the code) needs to be the same size of the right column (The

in the code), and vice versa. Also, if it helps, the yellow part is the

and the white background is the

. The

is just a container of the two columns and has no color.
I know that the “columns with same height” problem is a recurrent problem for web programmers, but the solutions I tried so far didn’t worked. I really wouldn’t like the “Faux Column solution” because, as I am a newbie in CSS, I didn’t want to appeal to a workaround like this one. If possible, I’d rather stick to pure CSS.
In advance, thanks for those who’ll be willing to help.

Solutions/Answers:

Solution 1:

The one that has always worked for me is:

#myPWrap,#otherPWrap {
  overflow:hidden;
}

#myP,#otherP {
  margin-bottom: -99999px;
  padding-bottom: 99999px;
}

You can also try to turn the wrap into a table and the #myP into a table col.

#myPWrap,#otherPWrap {
 display: table;
}

#myP,#otherP {
 display: table-cell;
}

Solution 2:

I solved this with a custom jQuery max plugin:

$.fn.max = function(selector) { 
    return Math.max.apply(null, this.map(function(index, el) { return selector.apply(el); }).get() ); 
}

Here content-box is my internal column element, content-container is the wrapper that contains the columns:

$('.content-box').height(function () {
  var maxHeight = $(this).closest('.content-container').find('.content-box')
                  .max( function () {
                    return $(this).height();
                  });
  return maxHeight;
})

Hope this helps.

Related:  Trouble interacting with Bootstrap modals via Capybara (v2)

References