Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make two columns the same height

I'm trying to make a 2 column design (using Twitter Bootstrap) with 2 columns of equal height.

Let's take this example:

<div class="row-fluid">
    <div class="span2">
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
            <li>Item 4</li>
        </ul>
    </div>

    <div class="span10">
        test
    </div>
</div>

​ Because .span2 is the highest of the two columns, it makes .row-fluid stretch to accommodate its height. After reading this article, I was expecting that setting min-height: 100% on .span10 would make it stretch to the full height, but it doesn't:

Screenshot

http://jsfiddle.net/WTNeB/1/

Why is that? Any solution to make .span10 stretch to its parent height, avoiding setting a fixed height, to keep this design flexible?

like image 459
BenMorel Avatar asked Sep 11 '12 18:09

BenMorel


1 Answers

Try this:

http://jsfiddle.net/WTNeB/2/

notice that i added display:table and display:table-cell but also I changed the css selector names so that it gets the priority needed.

.row-fluid {
    border: 1px dotted gray;
    display: table;
}
.row-fluid .span2 {
    border: 1px solid blue;
    display: table-cell;
    float: none;
}
.row-fluid .span10 {
    min-height: 100%;
    border: 1px solid red;
    height: 100%;
    display: table-cell;
    float: none;
}
like image 131
samura Avatar answered Oct 23 '22 08:10

samura