Vivendi
Vivendi

Reputation: 20997

Relative DIV with auto width

I have a div with an image and a label in it. The label must be ontop of the image so i made the outer container div relative.

But i also want that the container div has the same width as the image. So i can set a 100% width on my label. I also don't know the width of the image before hand. This is loaded dynamically.

But the container div always has a 100% width set to it. Is there any way to let it have the width of the image that is inside?

Example: http://jsfiddle.net/sbNZu/391/

Upvotes: 0

Views: 53

Answers (1)

j08691
j08691

Reputation: 207861

Do one of the following rules to your container:

  1. Add a display:inline-block
  2. Add float:left

Either will shrink the container div to fit the contents.

Upvotes: 1

Related Questions