Can I ever use a div in a paragraph??

Discussion in 'HTML' started by Andrew, Jan 9, 2007.

  1. Andrew

    Andrew Guest

    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

    --
    The STRONG Family Web Site
    http://www.strong-family.org
     
    Andrew, Jan 9, 2007
    #1
    1. Advertising

  2. Andrew

    Bergamot Guest

    Andrew wrote:
    >
    > Are there any circumstances where I can put a <div> inside a <p>


    No. Per the DTD
    <!ELEMENT P - O (%inline;)* -- paragraph -->

    This means it can only contain inline elements. Div is a block element.

    > or is
    > this just part of using a Strict Doctype?


    This rule is the same for all DOCTYPEs.
    http://www.w3.org/TR/html401/struct/text.html#edef-P

    --
    Berg
     
    Bergamot, Jan 9, 2007
    #2
    1. Advertising

  3. Andrew

    dorayme Guest

    In article <>,
    Andrew <> wrote:

    > 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.

    --
    dorayme
     
    dorayme, Jan 9, 2007
    #3
  4. Andrew

    Neredbojias Guest

    To further the education of mankind, Andrew <>
    vouchsafed:

    > 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.

    > 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
    >




    --
    Neredbojias
    Infinity has its limits.
     
    Neredbojias, Jan 9, 2007
    #4
  5. Andrew

    Toby Inkster Guest

    Neredbojias wrote:

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


    CSS can never make any difference to XHTML validation.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Jan 9, 2007
    #5
  6. Andrew

    Toby Inkster Guest

    Andrew wrote:

    > 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.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Jan 9, 2007
    #6
  7. Andrew

    Steve Pugh Guest

    Neredbojias wrote:
    > To further the education of mankind, Andrew <>
    > vouchsafed:
    > >
    > > 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.


    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
     
    Steve Pugh, Jan 9, 2007
    #7
  8. Scripsit Neredbojias:

    >> 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?


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

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Jan 9, 2007
    #8
  9. Scripsit dorayme:

    >> 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.


    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.

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Jan 9, 2007
    #9
  10. Andrew

    Andrew Guest

    On Tue, 09 Jan 2007 09:17:41 +0000, Toby Inkster wrote:

    > Andrew wrote:
    >
    >> 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.


    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>>>>>>

    >> 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.


    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

    --
    The STRONG Family Web Site
    http://www.strong-family.org
     
    Andrew, Jan 9, 2007
    #10
  11. Andrew

    Andrew Guest

    On Tue, 09 Jan 2007 11:55:35 +0200, Jukka K. Korpela wrote:

    > Scripsit Neredbojias:
    >
    >>> 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?

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


    The CSS for the captioned images that I am using actually came from your
    site:

    http://www.cs.tut.fi/~jkorpela/www/captions.html

    Of course the error with the placement of the <div>s was my own
    contribution :)

    Andrew

    --
    The STRONG Family Web Site
    http://www.strong-family.org
     
    Andrew, Jan 9, 2007
    #11
  12. Andrew

    Andrew Guest

    On Mon, 08 Jan 2007 23:42:09 -0500, Neredbojias wrote:

    > To further the education of mankind, Andrew <>
    > vouchsafed:
    >
    >> 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.
    >

    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

    --
    The STRONG Family Web Site
    http://www.strong-family.org
     
    Andrew, Jan 9, 2007
    #12
  13. Andrew wrote:
    > 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?
     
    Harlan Messinger, Jan 9, 2007
    #13
  14. Andrew

    dorayme Guest

    In article <8FKoh.160$>,
    "Jukka K. Korpela" <> wrote:

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


    >
    > > 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.


    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.

    --
    dorayme
     
    dorayme, Jan 9, 2007
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J Rice
    Replies:
    2
    Views:
    706
    J Rice
    Jul 25, 2006
  2. Replies:
    18
    Views:
    628
    Michael Winter
    Oct 27, 2006
  3. dorayme
    Replies:
    112
    Views:
    2,822
    dorayme
    Mar 30, 2009
  4. Jason
    Replies:
    0
    Views:
    219
    Jason
    Jul 6, 2004
  5. Dave
    Replies:
    2
    Views:
    139
Loading...

Share This Page