Can I ever use a div in a paragraph??

A

Andrew

Hi,

I am currently adding captions to images in a large site and made the
mistake of trying to place a <div> element inside a <p> element and
consequently failed validation using XHTML Strict 1.0. A corrected
example is here:

http://www.strong-family.org/foster/chapter_3.html

Are there any circumstances where I can put a <div> inside a <p> or is
this just part of using a Strict Doctype?

BTW are there any Bluefish Editor users here? I have just moved to Linux
(Xubuntu 6.06) and discovered this great editor: helpful but not too
intrusive :)

Andrew
 
D

dorayme

Andrew said:
Are there any circumstances where I can put a <div> inside a <p> or is
this just part of using a Strict Doctype?

No you cannot do this. But can you think of a circumstance in
which you had a paragraph which suddenly broke out into a
rectangle underneath with something in it like a pic or movie and
then continued after with text and still be rightly a paragraph
in the ordinary understanding of this item? Surely not.
 
N

Neredbojias

Hi,

I am currently adding captions to images in a large site and made the
mistake of trying to place a <div> element inside a <p> element and
consequently failed validation using XHTML Strict 1.0.

Did you revalidate it after changing the div styles to display:inline?
- Just curious.
 
T

Toby Inkster

Neredbojias said:
Did you revalidate it after changing the div styles to display:inline?
- Just curious.

CSS can never make any difference to XHTML validation.
 
T

Toby Inkster

Andrew said:
Are there any circumstances where I can put a <div> inside a <p> or is
this just part of using a Strict Doctype?

Yes:

<p><object><div>Foo</div></object></p>

Also, APPLET and NOSCRIPT will work instead of OBJECT. Possibly IFRAME as
well -- I'm too lazy to check. None of them will help you though. Really
you need to replace your DIV element with an inline element such as SPAN.

Nothing to do with the Strict doctype -- the same is the case in
Transitional.
BTW are there any Bluefish Editor users here? I have just moved to Linux
(Xubuntu 6.06) and discovered this great editor: helpful but not too
intrusive :)

If you like Bluefish, take a look at Screem. I prefer Nedit and SciTE
though.
 
S

Steve Pugh

Neredbojias said:
Did you revalidate it after changing the div styles to display:inline?
- Just curious.

Why would that make any difference? Changing the style of an element
only changes how it is presented, not what it actually is. Hence, you
can see why validating HTML only validates the HTML, anything in the
CSS is 100% irrelevant.

Steve
 
J

Jukka K. Korpela

Scripsit Neredbojias:
Did you revalidate it after changing the div styles to display:inline?

That would be pointless, since adding a _CSS_ rule cannot possibly affect
the validity of _markup_ (HTML).
 
J

Jukka K. Korpela

Scripsit dorayme:
No you cannot do this.

You cannot, and the simple reason is that none of the HTML document types
allows that. Well, you _can_ do it, but the markup is then invalid and the
results are more or less unpredictable, especially in future browser
versions.

But there's no "deeper" reason to this. It's just a matter of HTML syntax,
which was defined somewhat arbitrarily in this respect, perhaps partly for
technical reasons (to make the world safe for simplistic browsers).

The OP has solved the problem nicely by putting the image and the caption in
a div element _before_ the paragraph and using CSS to make it appear the
same way you could do for a simple image using <img ... align="right">. One
could also use a two-cell table, with the image and the caption text in
separate cells and with align="left". It would be valid as Transitional,
though not acceptable by all Purists' standards.
But can you think of a circumstance in
which you had a paragraph which suddenly broke out into a
rectangle underneath with something in it like a pic or movie and
then continued after with text and still be rightly a paragraph
in the ordinary understanding of this item? Surely not.

I can, without problems. Actually I often run into such situations. For
example, I might find myself writing something that needs to be illustrated
with an image or a long formula or a multi-line code snippet inside a
paragraph, since the explanation continues after it in a natural way. Surely
I can use just <img ...> for an image, and I can use <br><img ...><br> to
make it appear in a line of its own. But why should things get radically
different if the image needs a caption below it? I _can_ fool the syntax
restrictions by using <br><span class="image"><img ...><br><span
class="caption">caption text</span><br> and some CSS to style the construct,
but that would really be just a workaround in a situation where I _wanted_
to use <div>. (Well, I _really_ wanted to use <fig>, but they never added it
to the specifications and never implemented it.)

To summarize: Live with the restrictions, but there's no need to make the
restrictions a virtue.
 
A

Andrew

Yes:

<p><object><div>Foo</div></object></p>

Also, APPLET and NOSCRIPT will work instead of OBJECT. Possibly IFRAME as
well -- I'm too lazy to check. None of them will help you though. Really
you need to replace your DIV element with an inline element such as SPAN.

Thanks, I was not aware of this. In this particular case (captions added
to images) I will stick to DIVs of fixed width floated right or
left with paragraph text wrapped around. Seems to work well enough on the
site:

http://www.strong-family.org/foster

but I will file away the info on using SPAN for another day / situation.

snip>>>>>>
If you like Bluefish, take a look at Screem. I prefer Nedit and SciTE
though.

Thanks for that! Nedit and SciTE look a little too bare-bones for my
taste but I shall have a closer look at Screem. I notice that it has link
checking which would be a big help on the Genealogy site I am working on.

Thanks again,

Andrew
 
A

Andrew

Did you revalidate it after changing the div styles to display:inline?
- Just curious.
snip >>>>>>>

After I moved the position of the <div> it certainly validated. Do you
mean the inline style I have used for width of the div? :

<div class="captionL" style="width:211px;">image details here </div>

Yes, this validated.

Thanks for your trouble,

Andrew
 
H

Harlan Messinger

Andrew said:
Hi,

I am currently adding captions to images in a large site and made the
mistake of trying to place a <div> element inside a <p> element and
consequently failed validation using XHTML Strict 1.0. A corrected
example is here:

http://www.strong-family.org/foster/chapter_3.html

Are there any circumstances where I can put a <div> inside a <p> or is
this just part of using a Strict Doctype?

DIV has never been allowed inside a P in any version of HTML.

What is it about the entirety of the material you have inside this P
element, including the DIV, that you see as amounting to a single paragraph?
 
D

dorayme

"Jukka K. Korpela said:
Scripsit dorayme:


I can, without problems. Actually I often run into such situations. For
example, I might find myself writing something that needs to be illustrated
with an image or a long formula or a multi-line code snippet inside a
paragraph, since the explanation continues after it in a natural way.

I guess I was being miserably "typographical" in thinking of a
paragraph as a block of text with a continuous "thought" to the
sentences. Your idea is more generous, a class of grouped
thoughts that can include line breaks and pics and things. I like
your idea better even if it is a little harder to define.

About this business of definition, I am not talking of some
prissy dictionary definition but rather a general understanding
of what constitutes a paragraph. When has one made a mistake in
identifying the number of paragraphs in a block of text or page.
So far, my reply has contained 2 paragraphs under the simple
"typographical" idea. This is not to say it could not have been
less or more, given the thoughts I have expressed. But it is
clearly 2, right or wrong.

But if one imagines a page or more with pics and movies and
formulae on separate lines, I would say this sort of thing is
harder to count, especially for writers who are not the best and
clearest in their consciousness of what they are doing.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top