Goran
Goran

Reputation: 1837

CSS width problem child parent

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.

Upvotes: 3

Views: 7627

Answers (3)

Joel Glovier
Joel Glovier

Reputation: 7679

You can use the following code to achieve your result:

#b {
  margin:0px auto;
  overflow:hidden;
  display:table;
}

This should give your desired result.

Upvotes: 6

Matthew Jones
Matthew Jones

Reputation: 26190

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

Upvotes: 3

Guffa
Guffa

Reputation: 700352

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

<div id="B" style="float:left;">

Upvotes: 3

Related Questions