Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

<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.

like image 276
Falassion Avatar asked Feb 08 '12 22:02

Falassion


People also ask

How do I make two equal columns in Bootstrap?

Use the . col class on a specified number of elements and Bootstrap will recognize how many elements there are (and create equal-width columns). In the example below, we use three col elements, which gets a width of 33.33% each.

How can I make Bootstrap columns all the same height?

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.

How do I make Bootstrap 4 columns equal height?

You just have to use class="row-eq-height" with your class="row" to get equal height columns for previous bootstrap versions.

How do I put two columns together in HTML?

To merge table columns in HTML use the colspan attribute in <td> tag. With this, merge cells with each other. For example, if your table is having 4 rows and 4 columns, then with colspan attribute, you can easily merge 2 or even 3 of the table cells.


1 Answers

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;
}
like image 193
filype Avatar answered Sep 22 '22 23:09

filype