How to fit equal height for two columns, which are in a centered container?

Go To StackoverFlow.com

1

How can I create equal height columns in CSS? All I have found searching the Internet was for one color background, but I have a white background. Every column must have a rounded border, and the left column may have many containers inside. How do I create this, such that the columns are equal, by which I mean left and right? Also, how can I do that if the height of the right column is smaller than the left, as in the photo? It must be stretched.

enter image description here

2012-04-05 19:02
by byCoder


1

You can use display table. Doesn't play nice with IE7 unfortunately. Although I encourage people to drop support for it. My company just did. There are other techniques available here, but I think semantically this is the most elegant.

http://css-tricks.com/fluid-width-equal-height-columns/

http://jsfiddle.net/7HgwA/1

CSS

body { padding: 10px; }
#container { 
    display: table; 
    width: 600px; 
    margin: 0 auto; 
    overflow: auto; 
    border: 1px solid gray; 
    border-radius: 20px; 
    padding: 10px; 
}

#container > div { display: table-cell; }
#container div { border: 1px solid gray; border-radius: 20px; padding: 20px;  }
#left > div { height: 100px; margin-bottom: 10px; background: white; } 

#left { width: 150px;  background: lightgray; }
#container #spacer { width: 20px; border: none; padding: 0px; }

HTML

<div id="container">
    <div id="left">
        <div>Some content</div>
        <div>Some content</div>
        <div>Some content</div>
        <div>Some content</div>
    </div>
    <div id="spacer"></div>
    <div id="right">
        <p>Lorem ipsum dolor sit</p>
    </div>
</div>​
2012-04-05 19:18
by mrtsherman
sorry, many peoples in Russia and Belarus yet use ie 6! and - byCoder 2012-04-05 19:21
@pavel - sorry to hear that! According to statcounter Belarus only has 2% IE7 users and it doesn't even make top 12 for Russia. Maybe fewer people use it than you think! Also, MS is force upgrading users to IE8/9 starting in March of this year. Brazil and south america were the first to go. http://gs.statcounter.com/#browser_version-BY-monthly-201103-201203-ba - mrtsherman 2012-04-05 19:27
) according to this site, what I do, it's peoples that doesn't know what is browser)) so thay use standart.. - byCoder 2012-04-05 19:50
Ads