tags:

views:

54

answers:

3

I have a container div with a floating left-hand navigation pane and a content pane to the right:

<div id="header"></div>
<div id="container">
    <div id="leftnav"></div>
    <div id="content"></div>
    <div class="clearfix"></div>
</div>
<div id="footer"></div>

CSS:

body
{
    text-align: center; /* IE center div fix */
}

#container
{
    width: 800px; /* site width */
    background-color: red; /* so I can see it */
    text-align: left; /* undo text-align: center; */
    margin: 0 auto; /* standards-compliant centering */
}

#leftnav
{
    float: left;
    width: 200px;
}

#content
{
    height: 100%;
    width: 600px;
    margin-left: 200px;
    background-color: green; /* so I can see it */
}

.clearfix { clear: both; }

The #container div stretches to the full height of the floating #leftnav div, but the contained #content div does not stretch to 100% of the height. I've read elsewhere that this is due to the parent #container not having a specified height (defaults to auto) and therefore the 100% is not based on that container; however, I can't specify the height because the left navigation pane height isn't constant.

How can I get the #content div to be 100% of the height of the #container div when the #container div's height is defined by the floating #leftnav?

A: 

The easy way would be to use JS to set the height of #content to the height of #leftnav. You can use faux columns on #container and make a slice/gif of the green background and repeat it vertically on #container along with the red however you have it but I'm not sure if it fits your needs.

meder
I'm trying to avoid a JavaScript solution. I know it'd take all of 4 seconds to get to work in a cross-browser-compatible way, but the ideal solution here would be pure CSS/XHTML.
Scott R
+1  A: 

This is similar to the 3 column liquid "holy grail" CSS layout that has been plaguing people for years (though has been solved in the past couple years, though many of the solutions required browser hacks or Javascript to function).

I'd highly suggest you not reinvent the wheel here as it is difficult to get CSS to perform exactly as you're describing. Here is a good resource for this layout and many other similar liquid layouts: http://matthewjamestaylor.com/blog/perfect-2-column-left-menu.htm

Adam Sills
I'm all through my upvotes, but this is more or less what I wanted to say.
Litso
The layout I have works just as well as the one in the link you provided; I'm open to suggestions, but the layout you linked is unstable with regards to reflow and content that isn't 100% of the viewport width, in addition to using overflow:hidden, which causes problems with another layout component I omitted from the question. Additionally, the linked layout doesn't force both columns to become the same height, just the parent container to become the height of the largest element - which I already have.
Scott R
I haven't tested the reflow behavior of that template, but it does everything you're asking about. Perhaps you just modified it incorrectly. You can adjust the width of the header/colmask to be whatever width you want, and both columns extend to the bottom of the containing element, regardless of whichever one is longer.
Adam Sills
I downloaded the test version from that website and added 'background: green' to .leftmenu .col1{}. Do that, and you'll see the behavior I'm referring to (.col1 is the right-hand content pane, the green background does not extend to the footer). Tested in Chrome 6.0.472.53 and Firefox 3.6.8. No other changes were made to the downloaded template.
Scott R
Right. If you add it to the correct style, then it looks fine :) Change the following styles background colors: ".leftmenu .colleft", ".leftmenu". Those are the container styles for the content. The styles themselves even say "left menu background color" and "right menu background color".
Adam Sills
Er, the styles say "left column background color" and "right column background color".
Adam Sills
A: 

try this CSS

body
{
    text-align: center; /* IE center div fix */
}

#container
{
    width: 800px; /* site width */
    background-color: red; /* so I can see it */
    text-align: left; /* undo text-align: center; */
    margin: 0 auto; /* standards-compliant centering */
}

#leftnav
{
    float: left;
    width: 200px;
}

#content
{
    height: 100%;
    width: 600px;

    background-color: green; /* so I can see it */
    float:right;
}

.clearfix { clear: both; }

I would also suggest using a line break with a clear both rather than a div.

JamesStuddart