tags:

views:

48

answers:

3

Let's say I want to have two columns. The right one is 200px wide, and the left one just takes up the remaining width. Is this possible? What do I set the width of the left column to be?

Rather than fighting with this for hours, I'll get your opinions first ;)

A: 

Yes, it is possible. Set the right column's style to float: right and width: 200px, and the left column will be the content and take up the rest of the width.

dmr
Don't forget to set the margin of the right part to 200px to, otherwise your text will get under the left column if it's shorter.
Radomir Dopieralski
+3  A: 

You float the left column and set margin to minimum of the width of the left column.

<div id="Container">
    <div id="LeftColumn" style="float: left; margin-right: 200px;"></div>
    <div id="RightColumn" style="float: right; width: 200px;"></div>
</div>

OR

<div id="Container">
    <div id="RightColumn" style="float: right; width: 200px;"></div>
    <div id="LeftColumn" style="margin-right: 200px;"></div>
</div>
Dustin Laine
I think you did it backwards to how I posted it... surely you mean to give the right column the fixed width and the left one the margin?
Mark
Correct, fixed answer. Thanks
Dustin Laine
Actually, you broke it ;) The right column is nudged down below the left now. Adding `float:left` to the left col too seems to fix the issue. http://jsfiddle.net/4k9Fj/
Mark
Check your link, and my update. You can use the same code but switch the order of columns in HTML. My mistake.
Dustin Laine
Actually, none of these solutions work really well w/ a background http://jsfiddle.net/bgBXM/I need the div to actually expand to take up the full space.
Mark
And when you add more content http://jsfiddle.net/P6YWr/ it just doesn't work at all
Mark
+2  A: 

If you don't want to float divs, you can do the following:

.rightDiv {
  position: absolute;
  right: 0;
  width: 200px;
}

.mainDiv {
  position: absolute;
  left: 0;
  right: 200px;
}
Robusto
I don't mind floats actually. I think you need to wrap these columns in a container that has `position:relative` in order to have the columns relative to the container, rather than the page, no?
Mark
@Mark: You don't have to have the columns in a container unless you want to limit the overall width of the page (i.e., not let it expand and contract with the width of the browser).
Robusto