"div" width problem

how to fix the width of div according to its content

Page 1 of 1

1 Replies - 1899 Views - Last Post: 05 September 2009 - 02:16 AM

#1 javedparamount  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 28-July 09

"div" width problem

Post icon  Posted 04 September 2009 - 11:56 PM

I am trying to set the width of a div element based on the size of an image that is within the div. I also have a text caption below the image in this same div and if the line goes longer than the width of the image than the div will be resized so that it doesn't fit so nicely around the image.

I don't want to define the width of the div because the image contained will vary in size.

I want to be able to specify that the div should only be as wide as the image and force the text to break and start new lines below rather than expanding the width of the div.

So i want to specify which child element controls the parent.

Is this possible in any way? If so, I'd love to know. Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: "div" width problem

#2 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: "div" width problem

Posted 05 September 2009 - 02:16 AM

View Postjavedparamount, on 5 Sep, 2009 - 05:56 AM, said:

I am trying to set the width of a div element based on the size of an image that is within the div. I also have a text caption below the image in this same div and if the line goes longer than the width of the image than the div will be resized so that it doesn't fit so nicely around the image.

I don't want to define the width of the div because the image contained will vary in size.

I want to be able to specify that the div should only be as wide as the image and force the text to break and start new lines below rather than expanding the width of the div.

So i want to specify which child element controls the parent.

Is this possible in any way? If so, I'd love to know. Thanks in advance

If you don't specify the size of the div, then it will expand to accomodate the image. If you put the text inside another div inside the biggun, or span or whatever, and set that to "width: 100%, overflow: hidden", then I would imagine it would do what you want.
<div>
<img />
<span style="width: 100%, overflow: hidden">blah</span>
</div>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1