tags:

views:

909

answers:

3

Hi...

I have a div C inside div B inside div A.

Div A has width set to 700px, and div C has width set to 100px. Div B doesn't have the width set.

My problem is that div B extends his width to 100% (to conform div A's width). Is there a way for div B, that is, his width to conform to children divs? I want it to be wrapped around div C, and any other div I put near div C.

+1  A: 

Make the B div a floating element to make it's width adjust to it's children.

<div id="B" style="float:left;">
Guffa
Hm, good answer... But I want to position those C divs, so they look like they are in the center of div A. If I put float:left to div B, I will not be able to do that.
Goran
If you want to center the B div it's easily done by setting the left and right margin to auto, but then you need to specify a width for it instead of floating it.
Guffa
Yes, but if I add width to div B, then I will not be able to automatically resize it when new divs C are added.
Goran
A: 

It sounds like what you want is the nonexistent float:center attribute. Check this article for a workaround.

Matthew Jones
A: 

is setting the left/right margin or padding to % an option?

Stephan