473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

span width/height from contained elements failing?

I've spent the last 2 days reading in waaay too much detail
the specs for CSS and HTML.

I am attempting something very simple. I wish to wrap
an image and caption in a span, so that the text can be centred
w.r.t the image, and a border (margin etc) be placed around them both.

This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.
I'll worry about the rest later.

My most careful reading of specs says that the following should
work. (I'm applying a bright red to make everything visible).

<html>
<head>
<title>test</title>
</head>

<style>

..big {
background-color: red;
padding:16px;
border:1px solid black;
}
</style>

<body>
<p>
<span class="big">
<img src="bigimg.gif" width="542" height="79"><br>
</span>
</p>

</body>
</html>

This should simply put a 16px red border around the image.

I get "strange" results, and they differ tremendously
amongst browsers. Only IE5.1.7 on MacOs9 gives the result
I want (which is not to say it's right of course).

Any advice and input would be more than welcome.

BugBear
Jul 21 '05 #1
6 18219
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
I've spent the last 2 days reading in waaay too much detail
the specs for CSS and HTML.
I'd say you've not spent nearly enough time reading the spec.
I am attempting something very simple. I wish to wrap
an image and caption in a span, so that the text can be centred
w.r.t the image, and a border (margin etc) be placed around them both.

This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.
Span defaults to inline, width specified on an inline element is ignored
as required by the spec.
Any advice and input would be more than welcome.


Tell us what you are actually trying to achieve if you want help with
the real problem.

--
Spartanicus
Jul 21 '05 #2
Spartanicus wrote:
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:

I've spent the last 2 days reading in waaay too much detail
the specs for CSS and HTML.

I'd say you've not spent nearly enough time reading the spec.


I know what you mean.

I am attempting something very simple. I wish to wrap
an image and caption in a span, so that the text can be centred
w.r.t the image, and a border (margin etc) be placed around them both.

This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.

Span defaults to inline, width specified on an inline element is ignored
as required by the spec.


Absolutely. You may note in the sample that I don't attempt
to set a width on the span.

http://www.w3.org/TR/REC-CSS2/visude...width-property
(quote)
This property does not apply to non-replaced inline-level elements. The
width of a non-replaced inline element's boxes is that of the rendered
content within them (before any relative offset of children).
(end quote)

This is exactly the behaviour I desire. My 2 days weren't wasted.
Tell us what you are actually trying to achieve if you want help with
the real problem.


I wish to associate/group an image and a caption, place a
coloured border around the 2 elements, and have the pair act as an
inline block.

BugBear
Jul 21 '05 #3
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
I wish to associate/group an image and a caption
There is no proper markup available to express relationship between an
image and a caption. Some would use a table to do that, imo that's
inappropriate usage of the table element. There are different views on
what to use if not a table, most would advocate using a div to group the
two, I'm of the opinion that a paragraph element can be preferable.
, place a
coloured border around the 2 elements, and have the pair act as an
inline block.


You've pretty much answered your own question here.

<div style="display:inline-block;border:1px solid red">
<img ...><br>
caption
</div>

Support for inline-block is limited, it's currently supported by recent
versions of Opera, Safari and iCab. It's also partially supported by
IE5+, but only on elements that default to inline.

It can be made more friendly to older browsers by setting the element to
inline-table first. The one problem that remains is Gecko based browsers
who lack support for any inline block element.

A cross browser (- Gecko) image & caption technique:
http://www.spartanicus.utvinternet.i...h_captions.htm
Borders can be added to this example.

--
Spartanicus
Jul 21 '05 #4
bugbear wrote:


This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.
I'll worry about the rest later.


From further reading, it appears that I require
the new, exotic and widely unavailable
"inline-block".

Can anyone explaine WHY I need this, and what
point I'm missing about
"non-replaced inline-level elements"

BugBear
Jul 21 '05 #5
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
bugbear wrote:

This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.
I'll worry about the rest later.
From further reading, it appears that I require
the new, exotic and widely unavailable
"inline-block".

Can anyone explaine WHY I need this,


You want the container to (a) only be as wide as the content, and to
have multiple such containers in a row, but (b) otherwise behave like
a box. That's a combination of inline and block behaviours, so
inline-block makes sense.
and what point I'm missing about
"non-replaced inline-level elements"


The relationship between inline elements (such as your span) and the
one or more line boxes that they may encompass is complex, espevially
when you have an inline replaced element (such as your image) inside
them. The image extends the height of the line box but not the height
of the inline box, or is it the other way round? See I said it was
complex.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 21 '05 #6
Steve Pugh wrote:
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
bugbear wrote:
This rapidly degenerated into an attempt to simple get
a span to be the size of a contained image.
I'll worry about the rest later.


From further reading, it appears that I require
the new, exotic and widely unavailable
"inline-block".

Can anyone explaine WHY I need this,

You want the container to (a) only be as wide as the content, and to
have multiple such containers in a row, but (b) otherwise behave like
a box. That's a combination of inline and block behaviours, so
inline-block makes sense.


OK. I think I understand that. Since inline-block is not yet widely
supported, I'm using a partial emulation.

In my (JSP generated) html, I've created a custom tag called
inlineBlock. It generates a table with a single cell.

This appears, in all the browsers I've tested, to give me most
of the properties of inline-block (as far as I understand these
properties and am able to test them ;-)

BugBear
Jul 21 '05 #7

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

Similar topics

3
by: kAldam | last post by:
I am currently using IE 6.0 and 5.5 and the scenario is the following. I have a span that contains text, and the span is beign contained by a table cell (this is the way thing need to be in my...
6
by: Christopher Benson-Manica | last post by:
http://ataru.gomen.org/files/html/files/test.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test page</title> <style...
6
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down...
10
by: lac | last post by:
Hello all, I am trying to make horizontal bars of different lengths. I tought either SPAN or DIV would work but it only works for IE. I have a small example at: http://sedivy.com/test.htm Let...
7
by: Luke Matuszewski | last post by:
Hi. I know that it is hard problem (as hard as CSS and HTML layouting rules apply), but maybe someone has some code or idea how to start it. For now i know i will cssQuery: ...
5
by: David Housman | last post by:
Hello, I'm trying to implement a navigation bar with a ul in css. The code is a template, but i'm customizing. I can handle just text in each block, but i want the first block to have an image...
5
by: Summercool | last post by:
wow... i didn't know that, for <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <span style="width: 100px; background:...
5
by: Brent | last post by:
Take this small HTML fragment: span.theClass{float:left;width:100px;cursor:pointer;cursor:hand;} ------------------------ <div> <span id="1" class="theClass">&nbsp;<span> <span id="2"...
6
by: liketofindoutwhy | last post by:
There is a link that encloses a span (or a div), but the link won't work in IE 7 (clicking on video image works, but not on the play button), while it works well in Firefox 2 and 3, and Safari 3....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.