tags:

views:

248

answers:

2

I'm wondering how to make two child divs share a parent div.

I want the left column to contain text from a database (one word). This could be 1-10 letters long. Since I want the left columns width to fit the word perfectly, I don't give it a set width.

Then, I was trying to have the right column fill the remaining space.

Is there an easy way to do this?

I'm not sure what to set the right column's css to make this happen.

<div id="parent_div" style="width: 100px; height: 100px;">
     <div style="background-color:blue; float:left;" id="left_column">
           blue
     </div>
     <div style="background-color:red; float: left;" id="right_column">
           red
     </div>
</div>

I read you shouldn't have something floated without giving it a set width, but then it seems like what I want would be impossible.

Thanks

A: 

Well, for a start, I would suggest that you make the right column float to the right - that should put it next to the left column. Not sure about the width of the left column though.

a_m0d
+1  A: 

I think you'll get the effect you want if you just don't float the second div.

<body>
<div id="parent_div" style="width: 100px; height: 100px;">
<div id="left_column" style="background-color: blue; float: left;"> blue </div>
<div id="right_column" style="background-color: red;"> red </div>
</div>
</body>

In firefox, this does exactly what you want. The red column takes up any remaining space not taken by the blue column.

womp
Man thanks a ton. I wish it wasnt this easy because now I look dumb.
No problem. You should mark answers as "accepted" if they solve your problem ;)
womp