16

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:

<div class="container">
 <div class="content">
 <div class="row">
 <div class="span8 div-content">
 <div class="center95">
 <div id="notWrap">
 <div id="not">
 </div>
 </div>
 </div>
 </div>
 <div class="span4 div-sidebar">
 <div class="center90">
 <div id="myPWrap">
 <div id="myP">
 </div>
 </div>
 <hr />
 <div id="otherPWrap">
 <div id="otherP">
 </div>
 </div>
 </div>
 </div>
 </div>
 </div>
 <footer id="bottom" class="footer">
 <p>&copy;</p> 
 </footer> 
</div>

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: project-pic

Basically, the left column (The <div class="span8 div-content"> in the code) needs to be the same size of the right column (The <div class="span4 div-sidebar"> in the code), and vice versa. Also, if it helps, the yellow part is the <div class="content"> and the white background is the <div class="container">. The <div class="row"> 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.

asked Feb 8, 2012 at 22:50
1
  • Did you look into a position: absolute; and top: 0;bottom: 0; ? If so, maybe fake the background with a border or a wrapper, and keep the background white. It just has to appear the same height. Commented Jul 1, 2012 at 20:36

2 Answers 2

6

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;
}
answered Feb 8, 2012 at 23:10
Sign up to request clarification or add additional context in comments.

3 Comments

Oh, I think I wasn't clear: the divs that must have the same sizes are the outer ones, the one with the "div-content" class and the one with the "div-sidebar" class. Similar solution, or it changes it all?
The same solutions should apply
which one? the second or the first snippet?
1

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.

answered Jan 18, 2013 at 8:18

Comments

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.