img tag in XHTML strict

T

tochiromifune

Hello,

My page fails the W3C validation test because my <img> tags are not
included in block level tags. Does that mean I must write:
<p><img src="" alt="" /></p>
instead of
<img src="" alt="" />

??

Thank you for your help
 
D

David Dorward

tochiromifune said:
My page fails the W3C validation test because my <img> tags are not
included in block level tags. Does that mean I must write:
<p><img src="" alt="" /></p>
instead of
<img src="" alt="" />

An image where the alternative text is a null string is unlikely to be a
paragraph. A div is more likely to be the most appropriate markup.
 
E

Els

David said:
An image where the alternative text is a null string is unlikely to be a
paragraph. A div is more likely to be the most appropriate markup.

If you just enclose your entire page in one div, it might save you
some code, depending on how many loose images you have in it.
 
A

Andy Dingley

My page fails the W3C validation test because my <img> tags are not
included in block level tags. Does that mean I must write:
<p><img src="" alt="" /></p>
instead of
<img src="" alt="" />

Probably <div>img src="" alt="" /></div> is better, but you're basically
right.

If it was reasonable to put <img> into a <p>, you'd probably already
have done it. If you want something that's more "anonymous" (for a
free-floating image not connected with any text), then use a <div>.
You might also wish to put a class on all these img-container <div>s,
just so you can easily control their CSS properties.
 
J

Jukka K. Korpela

Els said:
If you just enclose your entire page in one div, it might save you
some code, depending on how many loose images you have in it.

You save more code by using HTML 4.01 Transitional, which allows "loose"
content inside body and does not require all end tags.

If you wish to comply with a Strict DOCTYPE, then it's rather pointless to
use <body><div>...</div></body>, since the _idea_ in Strict is to put text
and inline markup inside _suitable_ blocks. If you don't care about the idea,
you could use Transitional, which does not require the pointless
<div> and </div> tags.
 
E

Els

Jukka said:
You save more code by using HTML 4.01 Transitional, which allows "loose"
content inside body and does not require all end tags.

If you wish to comply with a Strict DOCTYPE, then it's rather pointless to
use <body><div>...</div></body>, since the _idea_ in Strict is to put text
and inline markup inside _suitable_ blocks. If you don't care about the idea,
you could use Transitional, which does not require the pointless
<div> and </div> tags.

You're probably right about the Strict rules, but I think that having
loose images in a page isn't quite the same as switching to
Transitional altogether.
I always have my pages in a div, simply because I like to have the
option to add a border, a margin. I always have <body><div
id="container">....</div></body>
Often I give that container a left and right margin and a border
colour, or even a shadow effect.

And if I then have some decorative images floated left and right
within the content, I really don't see the problem if there isn't a
<div></div> around them. I think the rule that images and inline
content should be inside suitable blocks, wasn't invented for floating
decorative images, but for semantics. Decorative images aren't
semantic by definition, but because of the <img> element, they are
caught in the rule together with text that should be in paragraphs and
inline images. I prefer to look at the whole of an idea, instead of
scrutinously applying rigid rules without thinking about the reasons
for those rules. Unless there is a compatibility or accessibility
reason for putting decorative images in divs, I don't see the point,
and I find switching to Transitional an over the top measure to allow
loose images. Really, what's worse in your opinion: add a possibly
superfluous div, or change to a doctype that allows a bunch of
deprecated code?
 
N

Neredbojias

With neither quill nor qualm, Els quothed:
You're probably right about the Strict rules, but I think that having
loose images in a page isn't quite the same as switching to
Transitional altogether.
I always have my pages in a div, simply because I like to have the
option to add a border, a margin. I always have <body><div
id="container">....</div></body>
Often I give that container a left and right margin and a border
colour, or even a shadow effect.

And if I then have some decorative images floated left and right
within the content, I really don't see the problem if there isn't a
<div></div> around them. I think the rule that images and inline
content should be inside suitable blocks, wasn't invented for floating
decorative images, but for semantics. Decorative images aren't
semantic by definition, but because of the <img> element, they are
caught in the rule together with text that should be in paragraphs and
inline images. I prefer to look at the whole of an idea, instead of
scrutinously applying rigid rules without thinking about the reasons
for those rules. Unless there is a compatibility or accessibility
reason for putting decorative images in divs, I don't see the point,
and I find switching to Transitional an over the top measure to allow
loose images. Really, what's worse in your opinion: add a possibly
superfluous div, or change to a doctype that allows a bunch of
deprecated code?

I have (a few) pages where I don't use a doctype at all. Why? Simply
because they work better, -tested in IE, Mozilla&Firefox, and Opera. Of
course this is basically just "appealing to" quirks mode, but you and I
have already discussed issues relating to the vertical centering of
small content.

Surprisingly (at least to me) is that with some markup Mozilla and Opera
work better than IE even under this "quirks mode" auspices.
 
L

Leif K-Brooks

Els said:
I always have my pages in a div, simply because I like to have the
option to add a border, a margin. I always have <body><div
id="container">....</div></body>

You do realize that the body element can be styled, right?
 
E

Els

Leif said:
You do realize that the body element can be styled, right?

:)
And you do realize that the combination of html and body element is
much less manipulatable than the combination of html and body and div,
right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top