![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Could someone show me how to limit caption width to image width dynamically (image width is not known in advance) if that's possible? I was thinking of using Javascript to get the image width which is then used for caption width. Is there a better way? Thank you. I suppose this is too elementary. Contain the image and the caption in |
#3
| |||
| |||
|
|
Peter Parker wrote: Could someone show me how to limit caption width to image width dynamically (image width is not known in advance) if that's possible? I was thinking of using Javascript to get the image width which is then used for caption width. Is there a better way? Thank you. I suppose this is too elementary. Contain the image and the caption in a div with the same width as the image. If the image with caption is to be floated, the div will take the width of the image without it being actually declared on the div. |
#4
| |||
| |||
|
|
On 2007-05-06, boclair <boclair (AT) bigpond (DOT) net.au> wrote: Peter Parker wrote: Could someone show me how to limit caption width to image width dynamically (image width is not known in advance) if that's possible? I was thinking of using Javascript to get the image width which is then used for caption width. Is there a better way? Thank you. I suppose this is too elementary. Contain the image and the caption in a div with the same width as the image. If the image with caption is to be floated, the div will take the width of the image without it being actually declared on the div. Yes, although in that case the width it takes on will be the maximum of the image's width and the width of the caption (generally with no line breaks if enough space is available). This is probably a good thing though. |
#5
| |||
| |||
|
|
I suppose this is too elementary. Contain the image and the caption in a div with the same width as the image. If the image with caption is to be floated, the div will take the width of the image without it being actually declared on the div. Yes, although in that case the width it takes on will be the maximum of the image's width and the width of the caption (generally with no line breaks if enough space is available). This is probably a good thing though. Yes. However more often than not, the image will need to be bordered in which case the image needs to display block declared. This is what I had in mind. |
#6
| |||
| |||
|
|
Ben C wrote: On 2007-05-06, boclair <boclair (AT) bigpond (DOT) net.au> wrote: Peter Parker wrote: Could someone show me how to limit caption width to image width dynamically (image width is not known in advance) if that's possible? I was thinking of using Javascript to get the image width which is then used for caption width. Is there a better way? Thank you. I suppose this is too elementary. Contain the image and the caption in a div with the same width as the image. If the image with caption is to be floated, the div will take the width of the image without it being actually declared on the div. Yes, although in that case the width it takes on will be the maximum of the image's width and the width of the caption (generally with no line breaks if enough space is available). This is probably a good thing though. Yes. However more often than not, the image will need to be bordered in which case the image needs to display block declared. This is what I had in mind. |
#7
| |||
| |||
|
|
Scripsit boclair: I suppose this is too elementary. Contain the image and the caption in a div with the same width as the image. If the image with caption is to be floated, the div will take the width of the image without it being actually declared on the div. Yes, although in that case the width it takes on will be the maximum of the image's width and the width of the caption (generally with no line breaks if enough space is available). This is probably a good thing though. Yes. However more often than not, the image will need to be bordered in which case the image needs to display block declared. This is what I had in mind. I don't quite follow. How would bordering affect this? Usually if you want a border around an image, it's best to edit the image in an image processing program, adding a border. But in any case, you can set a border for an image in CSS (or HTML) without setting display: block. And I think you would still have the problem that for div style="float: right" img ...><br caption text /div the width would be determined by the caption text requirements, not the image width, when the caption is longer than the image width. |
|
So I think the only reasonable solution is to determine the width of the image (via server scripting, if the page is more or less dynamic) and set that width for the block. I think I found a tricky way though... table width="1" tr><td><img ...></td></tr tr><td>caption text</td></tr /table It's too tricky though, and there's no guarantee of success. |
#8
| |||
| |||
|
|
Scripsit boclair: Yes. However more often than not, the image will need to be bordered in which case the image needs to display block declared. This is what I had in mind. I don't quite follow. How would bordering affect this? Usually if you want a border around an image, it's best to edit the image in an image processing program, adding a border. But in any case, you can set a border for an image in CSS (or HTML) without setting display: block. |
![]() |
| Thread Tools | |
| Display Modes | |
| |