Question

Hey done a bit of digging and google search suggest a few cheat to get two columns of the same hight. Just a bit nervous as need to do this without bending any rules. Is there a way I can make the columns the same hights as each other i.e. main body and menu column being same regardless of how much content in either.

Using XHTML strict1.0.

Thanks

Damien

Was it helpful?

Solution

Add some fixed height approx. screen height and overflow: hidden for parent div. Add overflow : auto and height:100% for main div & sidebar. So that layout doesn't break when content grows.

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

<style type="text/css">
body                    {   font-family:Arial, Helvetica, sans-serif; font-size:12px; line-height:18px;  }
.clear                  {   clear:both; }
.container              {   background:#eee; display:inline-block; height:300px; overflow:hidden; padding:10px; width:800px;  } 
.container p,           {   color:#003;  }
.main                   {   background:#fff; float: right; height:100%; overflow:auto; padding:0 15px; text-align:justify; width:470px;  }
.main h1                {   color:#930;  }
.sidebar                {   background:#000; float:left; height:100%; overflow:auto; width:280px;    } 
.sidebar ul li a        {   color:#fff; text-decoration:none;    }
</style>

</head>

<body>

<div class="container">
        <div class="sidebar">
            <ul>
                <li><a href="#">Link -1</a></li>
                <li><a href="#">Link -2</a></li>
                <li><a href="#">Link -3</a></li>
            </ul>
        </div>

        <div class="main">
            <h1> Lipsum dot com </h1>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>

            <p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>

            <p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>

            <p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>


        </div>
        <br class="clear" />
</div>


</body>
</html>

I have made few changes to the CSS of the page, as per below comments you can check this out

<style type="text/css">
body                    {   font-family:Arial, Helvetica, sans-serif; font-size:12px; line-height:18px;  }
.clear                  {   clear:both; }
.container              {   background:#eee; display:block; overflow: hidden; position: relative; padding:10px !important; width:800px;  } 
.container p,           {   color:#003;  }
.main                   {   background:#fff; float: right; height:100%; overflow:auto; padding:0 15px; text-align:justify; width:470px;  }
.main h1                {   color:#930;  }
.sidebar                {   background:#000; float:left; height: 100%; left:10px;  position: absolute; width:280px; } 
.sidebar ul li a        {   color:#fff; text-decoration:none;    }
</style>

OTHER TIPS

Fiddle: http://jsfiddle.net/uYknh/

<div id="cols">
    <div class="col col1">
        asd<br/>asd<br/>asd<br/>asd<br/>asd<br/>asd<br/>
    </div>
    <div class="col col2">
        asd<br/>asd<br/>
    </div>
</div>

.cols{display:table-row;width:100%;}
.col{display:table-cell;width:230px;background-color:#eee;border:1px solid #555;}

HTML

<div id="main_body" class="custom_width"></div>
<div id="menu_column" class="custom_width"></div>

CSS

.custom_width {
    max-width: 400px;
}

Adjust the width accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top