#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Anacortes, WA, USA
    Posts
    5
    Rep Power
    0

    CSS: Control width of div with specific child element


    This may be impossible, but I thought I would ask:

    I am trying to set the width of a div element based on the size of an image that is within the div. Normally this isn't a problem, without a width being defined, the div will dynamically fit around the size of the image. However, 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

    being used for the photo caption here:
    http://philitopia.net/aonline/index.html
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    76
    Rep Power
    11
    not a very good solution but you can use a nested table there with width set to 1 to hold the image and caption.

IMN logo majestic logo threadwatch logo seochat tools logo