tags:

views:

45

answers:

3

I have a two column layout, using a container and a div called "left" and a div called "Right". How do I make sure that the div#right is only 500px, but div#left is as big as the user's browser will allow ...?

Here's what I have now:

<div id="container">
  <div id="left" style="float:left"> </div>
  <div id="right" style="float: right; width: 500px"> </div>
</div>
+3  A: 

Don't float the left div to the left. If you leave it "unfloated", then it will be the main content and automatically fill the available space.

dmr
Thank you very much
Zachary Burt
You're welcome- my pleasure! If this is your accepted answer, please accept it...
dmr
Is it possible to guarantee the left column a minimum width? I feel like now it's crushing the left column too for some reason, and leaving a bunch of extra space on the right.
Zachary Burt
I have to wait 6 minutes to accept the answer :)
Zachary Burt
Yes, there is a CSS min-width attribute.
dmr
this is my problem: http://devio.us/~zack/antfarm/
Zachary Burt
+2  A: 

You can do it by unfloating the #left div and giving it a padding-left that equals the #right div's width (this makes room for the right div). Finally, you'd need to swap the source order of both div's.

<div id="container">
    <div id="right" style="float: right; width: 100px; "> </div>
    <div id="left" style="padding-right: 100px; "> </div>
</div>

You can see it in action here.

Pat
It's giving me a weird result though. Pasting your code works fine in a solo page, but check out what it's doing in the context of my entire page:http://skitch.com/zacharyburt/dqhch/destroy-automatic-negative-thoughts
Zachary Burt
Do you mean how if you resize too small the #right column overlaps the content? You can fix that by setting a `min-width` on the #left column, which you'll have to hack with a CSS expression if you care about it working in IE6.
Pat
+1  A: 

Change style of you left div to:

<div id="left" style="margin-right:500px"></div>

This will make sure that content won't flow under the right floating div when content in the left one takes more vertical space than content in the right one.

Important

Don't forget to put the floated div in front of the unfloated one. So put your right one first in the markup and then the left one.

Solution to your particular problem

So you have two div elements

<div id="endants-content">
    <div id="screenshot-preview">...</div>
    <div id="endants-main-content">...</div>
</div>

And CSS should be like this to make it work as expected:

div#endants-content
{
    /* put min-width here is you need it */
}

div#screenshot-preview
{
    float:right;
    width:30%;
}

div#endants-main-content
{
    margin-right:30%;
    overflow:auto;
}
Robert Koritnik
it's not quite working ... c.f. http://devio.us/~zack/antfarm/
Zachary Burt
@Zachary Burt: Check my edited answer that solves your particular problem.
Robert Koritnik