473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Caption beneath an image

I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.

How can I cause the text of the caption to wrap so that it will stay
within the (varying) width of the image?

Any ideas?

Jul 20 '05 #1
8 3926
Wally wrote:
I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.

How can I cause the text of the caption to wrap so that it will stay
within the (varying) width of the image?


Put the image and caption in a div. Set the width of a div in pixels.
This might be a good use of inline style to set the width. You'll need
server side processing to accomplish this, e.g., a MySQL table with
image filename and width in pixels, and a php script to query the database.

--
Brian (remove "invalid" from my address to email me)
http://www.tsmchughs.com/
Jul 20 '05 #2
*Wally* <Wa*************@epa.state.il.us>:

I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.


<fig>
<img src="foo.img" alt="foo"><br>
<caption>Caption</caption>
</fig>

fig {display: inline-table; table-layout: fixed;}
fig>img, fig>caption {display: table-cell;}

or

<fig>
<img src="foo.img" alt="foo">
<caption>Caption</caption>
</fig>

fig {display: inline-table; table-layout: fixed; caption-side: bottom}
fig>img {display: table-cell;}
fig>caption {display: table-caption;}

As this list is not about HTML I won't give you advice which elements or
attributes to use. Yes, it does not work as intended in IE.

--
"We know it's summer when the rain's a wee bit warmer."
cab driver in Glasgow
Jul 20 '05 #3
Christoph Paeper <ch**************@nurfuerspam.de> wrote:
*Wally* <Wa*************@epa.state.il.us>:

I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.
<fig>
<img src="foo.img" alt="foo"><br>
<caption>Caption</caption>
</fig>


[more code snipped]
As this list is not about HTML I won't give you advice which elements or
attributes to use. Yes, it does not work as intended in IE.


More specifically, in case it wasn't clear to the OP, the above is not
HTML and won't help you if HTML is what you're writing. In that case,
you can use DIVs instead, with distinctive class names to attach the
styles to.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #4
*Harlan Messinger* <hm*******************@comcast.net>:
Christoph Paeper <ch**************@nurfuerspam.de> wrote:

<fig>
<img src="foo.img" alt="foo"><br>
<caption>Caption</caption>
</fig>
As this list is not about HTML I won't give you advice which elements or
attributes to use.


More specifically, (...), the above is not HTML


Actually it was inspired by the HTML 3.0 working draft, where it would have
been

<fig src="foo.img">
<caption>Caption</caption>
<p>Foo</p>
</fig>
and won't help you if HTML is what you're writing.
In a browser that styles arbitrary elements, too, it would, though.
In that case, you can use DIVs instead,


Depending on actual case, 'span' instead of 'fig' and maybe 'cite' for
'caption' would be appropriate. Perhaps with "span {display: inline-block}".
I wanted to spare us that discussion.

P.S.: br {display: $almost_anything} makes Opera 7.5 crash.

--
The Hitchhiker's Guide to the Galaxy:
"The Universe, as has been observed before, is an unsettlingly big place,
a fact which for the sake of a quiet life most people tend to ignore."
Jul 20 '05 #5
On Wed, 19 May 2004 03:42:27 +0200, Christoph Paeper
<ch**************@nurfuerspam.de> wrote:
*Wally* <Wa*************@epa.state.il.us>:

I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.
<fig>
<img src="foo.img" alt="foo"><br>
<caption>Caption</caption>
</fig>

fig {display: inline-table; table-layout: fixed;}
fig>img, fig>caption {display: table-cell;}


Are you trying to deliberately confuse poor Wally? For those readers who
are weaker in HTML, there certainly is no element <fig>. (In XML we might
see <pudding type="fig"> perhaps.)
As this list is not about HTML I won't give you advice which elements or
attributes to use. Yes, it does not work as intended in IE.


Are you then trying to say that it cannot be done in IE? Seems Brian
preceded you in this *list* with a solution that could.

Jul 20 '05 #6
Without claiming this is the best approach, at least it works. Here I
presume a float right; when I want to center the image, I comment the
float statement.

.caption-container {
text-align: center;
margin-top: 0.3em;
line-height: 9pt;
}
.caption {
font-size: smaller;
font-family: sans-serif;
}
#image-name {
background-color: transparent;
width: NNNpx;
height: NNNpx;
}
#image-container {
width: NNNpx;
margin-top: 0.3em;
margin-left: 0.3em;
float: right;
}
<div id="image-container">
<img id="image-name" src="NNN.png"
alt="[text identifier]" />
<div class="caption-container">
<span class="caption">
Caption text
</span>
</div>
</div>

--
Haines Brown
br****@hartford-hwp.com
kb****@arrl.net
www.hartford-hwp.com

Jul 20 '05 #7
*Neal* <ne*****@yahoo.com>:
On Wed, 19 May 2004 03:42:27 +0200, Christoph Paeper
<fig>
<img src="foo.img" alt="foo"><br>
<caption>Caption</caption>
</fig>
Are you trying to deliberately confuse poor Wally?


No. I was just trying to show a more general approach. A quick and dirty
solution was already there---the <br> is of course dirty, too. Usenet is
about discussing things, ending each thread after the first more or less
appropriate answer is not it.
For those readers who are weaker in HTML,
there certainly is no element <fig>.
As I said, it was in the HTML 3.0 draft. I used it as a stand-in for
something like "<div class="captioned-image">" and could have also called it
'foo'. Depending on context it doesn't have to be a 'div' or 'span' in HTML,
that's why I didn't use it.

If you want it to, it can be added with XHTML Modularization, though (<br>
becoming <br/>).
Yes, it does not work as intended in IE.


Are you then trying to say that it cannot be done in IE?


Not this approach, at least not in current versions of that µsoftware. Maybe
I should have written something like: "IE does not support the CSS used
above."
Seems Brian preceded you in this *list*
This is Usenet, not a list.
with a solution that could.


Wally didn't say he wanted a solution that works in IE. He didn't even say
he wanted a solution in HTML+CSS (let alone saying what he already tried). I
didn't say there was no way to achieve the desired rendition in IE6 or other
CSS1 browsers.
OTOH Brian's solution required adding image meta information (width in
pixels) to the mark-up either by hand, which he didn't mention, or by a
server-side script, which he unnecessarily restricted to PHP+DB.
A third, even dirtier but better supported, approach was an HTML table,
which would be off topic on ciwas.

--
"Music is essentially useless, as life is."
George Santayana
Jul 20 '05 #8
On Mon, 24 May 2004 14:24:45 +0200, Christoph Paeper
<ch**************@nurfuerspam.de> wrote:
*Neal* <ne*****@yahoo.com>:

Seems Brian preceded you in this *list*


This is Usenet, not a list.


You've missed the joke. In your previous post you wrote "As this list is
not about HTML I won't give you advice which elements or attributes to
use." (However, it could be argued that CSS begins with good markup, so
HTML is on-topic in that way...)
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1476
by: Abdalla Fawaz Elhawary | last post by:
can any body can help me to find a com that can read the image caption ... image caption : some images can store some data like image caption it's like text data and it can viewed from the...
6
2020
by: Michael Rozdoba | last post by:
I've tried to apply something along the lines of http://www.spartanicus.utvinternet.ie/test/caption_sized_to_image.htm to a floated span containing an image & caption, but I can't find anything...
2
5255
by: aqualizard | last post by:
I have made and image with a caption using CSS, but I am hoping someone can show me how to do it better. By better I mean less HTML, and hopefully have it work with any sized image where I do not...
1
2669
by: Eric | last post by:
I want to do the following using CSS, and I just can't seem to find the solution: There is some text here that describes some research or something that I'm doing. Part of the results of the...
11
4184
by: Tomek Toczyski | last post by:
What is the best way to attach a caption to an image in xhtml? I can attach a caption to a table by a "<caption>" tag but I would like to do sth similar to an image. How to do it in a natural...
11
4969
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html I've ended up with what seems like a rather complex structure for what I thought would be a somewhat simple...
7
5807
by: Peter Parker | last post by:
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...
0
1331
by: Pete Horrobin | last post by:
I'm having a problem getting a table caption to appear as desired in Firefox, and am wondering if anyone here might have an answer. Test page: http://www.horshamhc.co.uk/site07/captiontest.htm ...
5
1395
by: umeshj99 | last post by:
Hello! I want to know how to retrieve image caption using .NET. I have collected some information about IPTC and exif tags. I have a function where it retrieves image caption stored in tag 10e....
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.