473,657 Members | 2,282 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 3936
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>Captio n</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>Captio n</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>Captio n</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>Captio n</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>Captio n</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_anythin g} 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>Captio n</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>Captio n</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="captione d-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
1482
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 photoshop by clicking file-->Fileinfo i need a components to help me in this issue thankx alot
6
2027
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 that'll work in IE - floating seems to break it. Can it be done without having to specify each image's width explicitly? The best related info I could find was posted here a few days ago, but doesn't seem to work with floats in IE, unless I'm...
2
5262
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 have to hard code the width of the container that holds the image. Here is a description: I want to have an image with a caption underneath, aligned on the left. There should be a black keyline around the image, and the caption underneath, and...
1
2684
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 research is a graph that I want to display as Figure 1. +---------------------+ | | | |
11
4204
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 way? -tt.
11
4988
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 problem. Even that complex solution works well only in FireFox (haven't tested Safari...). Can anyone come up with a better solution, where 'better' means: - Works as well as the example above, but is simpler. OR
7
5814
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 is then used for caption width. Is there a better way? Thank you.
0
1337
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 The desired effect is for the caption to have curved corners at top left and right. This version tries to achieve this by coding the caption itself with the top right image, and an H2 within it having the top left image -- this
5
1405
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. However, this code does not work for many of the images. Please help. Public Function displaydetails(ByVal img1 As String) Dim s As String Dim i As Integer Dim j As Integer Dim encoding As System.Text.Encoding =...
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
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.