tags:

views:

43

answers:

1

Possible Duplicate:
CSS - Equal Height Columns?

There seems to be many articles on the web, but many are not updated and I can't understand if there is really a BEST way to build 2 equal columns in CSS (without knowing which one of them will be the longest).

Example:

alt text

What I want to achieve is that column B will strech all the way to the size of column A. Also, if column B will be longer than column A, then I want column A to strech all the way to the size of column B.

Thanks

Joel

A: 

This should work, ive seperated the specific styles needed, and commented where possible.

Hope it helps.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Equal 2cols</title>

<style type="text/css">
    /*common styles*/
        html, body, h1, h2, h3{margin:0; padding:0;}
        .clearme{clear:both;}

    /*generic layout styles*/
        #container{width:960px; margin:0 auto;}
        #header{width:960px; height:100px; background-color:#999; margin:0 0 10px 0;}
        #footer{width:960px; height:100px; background-color:#999; margin:10px 0 0 0;}

    /*equal height specific styles*/
        #layout{clear:left; float:left; width:100%; overflow:hidden; background:#f60; /* column 2 background colour */}
        #content{float:left; width:100%; position:relative; right:50%; background:#f00; /* column 1 background colour */}
        #col1 {float:left; width:46%; position:relative; left:52%; overflow:hidden;}
        #col2 {float:left; width:46%; position:relative; left:56%; overflow:hidden;}
</style>

</head>

<body>
    <div id="container">
        <div id="header">
            <h1>header</h1>
        </div><!--/#header-->

        <div id="layout">

            <div id="content">
                <div id="col1">
                    <h2>A</h2>
                </div><!--/#col1-->

                <div id="col2">
                    <h2>B</h2>
                    <p>As long as you like</p>
                </div><!--/#col2-->

            </div><!--/#content-->
        </div><!--/#layout-->

        <div class="clearme"></div>

        <div id="footer">
                <h3>Footer</h3>
        </div><!--/#footer-->

    </div><!--/#container-->
</body>
</html>
Rocket Ronnie