Closing paragraph tag required?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AndyZa

    Closing paragraph tag required?

    Is the following html valid?

    <p><hr width="50%"></p>

    Or would the following be more "technicall y correct"?

    <p>
    <hr width="50%">

    Do I require the closing </p> tag?

  • Benjamin Niemann

    #2
    Re: Closing paragraph tag required?

    AndyZa wrote:
    [color=blue]
    > Is the following html valid?
    >
    > <p><hr width="50%"></p>[/color]

    No.
    [color=blue]
    > Or would the following be more "technicall y correct"?
    >
    > <p>
    > <hr width="50%">[/color]

    Yes.
    [color=blue]
    > Do I require the closing </p> tag?[/color]

    No. The first example is equivalent to

    <p></p><hr width="50%"></p>

    which is obviously invalid, the second one is equivalent to

    <p>
    </p><hr width="50%">

    which is valid.

    The end tag for P is optional. HR is a block level element which is not
    allowed as a child of P. But a parser will not complain about this, because
    </p> is optional and the P element is implicitly closed.

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://pink.odahoda.de/

    Comment

    • Lars Eighner

      #3
      Re: Closing paragraph tag required?

      In our last episode,
      <1147953623.103 159.70390@g10g2 000cwb.googlegr oups.com>,
      the lovely and talented AndyZa
      broadcast on comp.infosystem s.www.authoring.html:
      [color=blue]
      > Is the following html valid?[/color]
      [color=blue]
      ><p><hr width="50%"></p>[/color]

      No. P cannot contain HR. The P element is closed when the HR is
      encountered.
      [color=blue]
      > Or would the following be more "technicall y correct"?[/color]
      [color=blue]
      ><p>
      ><hr width="50%">[/color]

      No. There is nothing in P. P means "this is a paragraph," not "make some
      space."
      [color=blue]
      > Do I require the closing </p> tag?[/color]

      In HTML 4x, the closing tag for P is optional. Your problem is that you
      appearently have not understood what HTML is all about. If you have a
      paragraph, mark it up with P. You seem to think P means something like:
      "skip a line here," which it doesn't. If I have misunderstood your
      intentions, please explain what sort document structure you are trying to
      represent when you attempt to put HR in P.


      --
      Lars Eighner usenet@larseigh ner.com http://www.larseighner.com/
      This would be the best of all possible worlds,
      if there were no religions in it. -- John Adams

      Comment

      • AndyZa

        #4
        Re: Closing paragraph tag required?

        > If you have a paragraph, mark it up with P. You seem to think P means something like:[color=blue]
        > "skip a line here," which it doesn't.[/color]

        You're spot on! I've amended my wicked ways...

        Comment

        • AndyZa

          #5
          Re: Closing paragraph tag required?

          > P means "this is a paragraph," not "make some space."

          What is the best way to "make some space"?

          Comment

          • David HÃ¥säther

            #6
            Re: Closing paragraph tag required?

            AndyZa <andyza@webmail .co.za> wrote:
            [color=blue][color=green]
            >> P means "this is a paragraph," not "make some space."[/color]
            >
            > What is the best way to "make some space"?[/color]

            Cascading Style Sheets.

            --
            David Håsäther

            Comment

            • Neredbojias

              #7
              Re: Closing paragraph tag required?

              To further the education of mankind, "AndyZa" <andyza@webmail .co.za>
              vouchsafed:
              [color=blue][color=green]
              >> P means "this is a paragraph," not "make some space."[/color]
              >
              > What is the best way to "make some space"?[/color]

              Eat a lot of beans beforehand.

              --
              Neredbojias
              Infinity has its limits.

              Comment

              • Andy Dingley

                #8
                Re: Closing paragraph tag required?


                AndyZa wrote:[color=blue][color=green]
                > > P means "this is a paragraph," not "make some space."[/color]
                >
                > What is the best way to "make some space"?[/color]

                Don't "make some space", just take the space you already have and make
                it look bigger.

                Rather than adding "space" (i.e. adding something to the content in
                your HTML document) instead take the "space" you already have (the
                break between HTML elements) and use CSS to define its rendering as
                being bigger than the default. Now you're just changing the
                presentation of the same content, which is generally agreed to be a
                better way of working.

                Learn some CSS (a good thing in general) and start with the margin
                properties. Ignore padding for the moment and learn CSS, CSS selectors,
                use of the class attribute and the notion of "collapsing margins".

                When you're happy with that, go on to learning about the "CSS box
                model", the use of padding and border, and the sorry world of IE bugs
                and the need for careful use of doctypes.

                Comment

                • phil-news-nospam@ipal.net

                  #9
                  Re: Closing paragraph tag required?

                  On Thu, 18 May 2006 14:08:35 +0200 Benjamin Niemann <pink@odahoda.d e> wrote:

                  | The end tag for P is optional. HR is a block level element which is not
                  | allowed as a child of P. But a parser will not complain about this, because
                  | </p> is optional and the P element is implicitly closed.

                  So what is the proper way to get the same effect as:
                  <hr noshade size=1 width="100%">
                  ?

                  A while back someone suggested <object> but that didn't work and they did
                  not follow up.

                  --
                  -----------------------------------------------------------------------------
                  | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
                  | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
                  -----------------------------------------------------------------------------

                  Comment

                  • phil-news-nospam@ipal.net

                    #10
                    Re: Closing paragraph tag required?

                    On 19 May 2006 02:01:30 -0700 "Andy Dingley <dingbat@codesm iths.com>" <dingbat@codesm iths.com> wrote:
                    |
                    | AndyZa wrote:
                    |> > P means "this is a paragraph," not "make some space."
                    |>
                    |> What is the best way to "make some space"?
                    |
                    | Don't "make some space", just take the space you already have and make
                    | it look bigger.
                    |
                    | Rather than adding "space" (i.e. adding something to the content in
                    | your HTML document) instead take the "space" you already have (the
                    | break between HTML elements) and use CSS to define its rendering as
                    | being bigger than the default. Now you're just changing the
                    | presentation of the same content, which is generally agreed to be a
                    | better way of working.
                    |
                    | Learn some CSS (a good thing in general) and start with the margin
                    | properties. Ignore padding for the moment and learn CSS, CSS selectors,
                    | use of the class attribute and the notion of "collapsing margins".
                    |
                    | When you're happy with that, go on to learning about the "CSS box
                    | model", the use of padding and border, and the sorry world of IE bugs
                    | and the need for careful use of doctypes.

                    What about making a horizontal rule? Wouldn't you have to add something
                    to the HTML so you can select it to do something like border-top:1px ?

                    --
                    -----------------------------------------------------------------------------
                    | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
                    | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
                    -----------------------------------------------------------------------------

                    Comment

                    • Jukka K. Korpela

                      #11
                      A modern way of replacing &lt;hr noshade size=1 width=&quot;100 %&quot;&gt;

                      Under Subject: Re: Closing paragraph tag required?
                      phil-news-nospam@ipal.net <phil-news-nospam@ipal.net > scripsit:
                      [color=blue]
                      > On Thu, 18 May 2006 14:08:35 +0200 Benjamin Niemann <pink@odahoda.d e>
                      > wrote:
                      >[color=green]
                      >> The end tag for P is optional. HR is a block level element which is
                      >> not allowed as a child of P. But a parser will not complain about
                      >> this, because </p> is optional and the P element is implicitly
                      >> closed.[/color]
                      >
                      > So what is the proper way to get the same effect as:
                      > <hr noshade size=1 width="100%">
                      > ?[/color]

                      How does that question relate to what you quoted, or how does it fall under
                      the Subject line "Closing paragraph tag required?"? Please start a new
                      thread with a fresh Subject when you raise a completely new issue.

                      I guess there are three schools of thought:

                      1) <hr noshade size=1 width="100%"> is OK. It's not Puristically correct,
                      but there's really no harm. If you have several <hr> elements, you would
                      find it easier to style them in CSS, but actually CSS will override the
                      presentational attributes if needed, so there's little reason to clean up
                      the markup on _existing_ pages.

                      2) Just use <hr> in HTML and try to find suitable CSS that corresponds to
                      the (partly unspecified and browser-dependent) rendering of <hr ...>, e.g.
                      hr { border-top: solid 1px #999; height: 0; width: 100%; }

                      3) Remove the <hr> and set a bottom border for the preceding element or a
                      top border for the following element, with suitable padding and/or margin
                      settings. The drawback is that in non-CSS rendering, the possible idea of a
                      divider between major parts of a document has been lost.

                      If you ask me, 2) is the best approach, 1) is acceptable too, and 3) is
                      often acceptable and even the best approach when the ruler would be esthetic
                      rather than a divider.
                      [color=blue]
                      > A while back someone suggested <object> but that didn't work and they
                      > did not follow up.[/color]

                      Perhaps the regulars regarded it as too foolish an idea to be even commented
                      on.

                      Comment

                      • Andy Dingley

                        #12
                        Re: Closing paragraph tag required?


                        phil-news-nospam@ipal.net wrote:
                        [color=blue]
                        > What about making a horizontal rule? Wouldn't you have to add something
                        > to the HTML so you can select it to do something like border-top:1px ?[/color]

                        That would be influenced by things like collapsing margins and whether
                        we actually wished for a "break" or "rule" element to be output.

                        If you want an extra break between paras, then use a <br> This is
                        often required when working with floated <div>s, because you really
                        can't achieve the necessary results by applying clever CSS to the
                        visible <div>s themselves - there just aren't enough "hooks" to hang
                        the varying CSS from.

                        If you want a visible rule, then use a <hr>. Although you can make many
                        sorts of underscore appear by simply setting the border-bottom
                        property, it's generally better to code these as an explicit <hr>
                        element. This gives better (i.e. more intuitive) behaviour from
                        collapsing vertical margins with the default <div> content elements.
                        It's also an easy hook if you wanted to replace a simple horizontal
                        rule with some florid Victorian curlicue (turn off the borders of the
                        <hr> and add a background-image)

                        Comment

                        • Alan J. Flavell

                          #13
                          Re: Closing paragraph tag required?

                          On Mon, 22 May 2006, Andy Dingley <dingbat@codesm iths.com> wrote:
                          [color=blue]
                          > If you want an extra break between paras, then use a <br>[/color]
                          ^^^^^^^

                          Was that meant to be theory or practice?

                          <br> is defined to be a line break. If there's no line to be broken,
                          then it's undefined what to do with <br>. What's more, in strict HTML
                          <br> is syntactically invalid outside of a suitable block element.

                          While it's true that most implementations interpret <br> as an
                          explicit newline request, rather than as a line break, I don't know
                          anything in the authoritative specifications which requires that, and
                          some browsers certainly have treated redundant <br> by simply ignoring
                          them.
                          [color=blue]
                          > This is often required when working with floated <div>s, because you
                          > really can't achieve the necessary results by applying clever CSS to
                          > the visible <div>s themselves - there just aren't enough "hooks" to
                          > hang the varying CSS from.[/color]

                          Any comments on http://positioniseverything.net/easyclearing.html ?

                          cheers

                          Comment

                          • Jukka K. Korpela

                            #14
                            Re: Closing paragraph tag required?

                            dingbat@codesmi ths.com <dingbat@codesm iths.com> scripsit:
                            [color=blue]
                            > If you want an extra break between paras, then use a <br>[/color]

                            Huh? What "extra break"? Why? In
                            <p>...</p><br><p>...</p>
                            (which seems to be what you suggest), the logical interpretation is that
                            <br> has no effect, since there is no line to be broken. Browsers are known
                            to do strange things with such <br> tags, but are you really recommending
                            that we rely on such (mis)behavior, which has some rough effect, instead of
                            the finer tuning achievable using CSS?
                            [color=blue]
                            > This is
                            > often required when working with floated <div>s,[/color]

                            I don't buy the idea, but anyway, this was about para(graph)s, not arbitrary
                            <div>s.
                            [color=blue]
                            > If you want a visible rule, then use a <hr>.[/color]

                            As I wrote under a different heading, in an attempt to make the Subject line
                            relate to the content, this really depends. The <hr> element is best
                            regarded as a logical divider, in the spirit of the good old HTML 2.0. Thus,
                            the question is whether the visible rule would be a manifestation of a
                            logical division, or just something cute and stylish.

                            Comment

                            • Andy Dingley

                              #15
                              Re: Closing paragraph tag required?


                              Alan J. Flavell wrote:[color=blue]
                              > On Mon, 22 May 2006, Andy Dingley <dingbat@codesm iths.com> wrote:
                              >[color=green]
                              > > If you want an extra break between paras, then use a <br>[/color]
                              > ^^^^^^^
                              >
                              > Was that meant to be theory or practice?
                              >
                              > <br> is defined to be a line break. If there's no line to be broken,
                              > then it's undefined what to do with <br>. What's more, in strict HTML
                              > <br> is syntactically invalid outside of a suitable block element.[/color]

                              That's an interesting question.

                              This is DTD-valid, but is it good practice?

                              <div id="big-overall-wrapper" >
                              <div>Paragrap hs and paragraphs of lorem ispsum</div>
                              <br>
                              <div>Even more wibble, several paras thereof</div>
                              </div>

                              You're right - <br> is intended as a line break. Now which is the
                              least-worst of these options?

                              - Use <br> in this case, because it's DTD-valid and a "reasonable "
                              extrapolation of "break"

                              - Use <hr>, with the visible rendering turned off, because it's a
                              "divider" after all

                              - Use an empty <div></div>, because that's the most strictly valid,
                              even though hardly meaningful.


                              [color=blue]
                              > Any comments on http://positioniseverything.net/easyclearing.html ?[/color]

                              OK for the trivial case, but you can still generate a complex case
                              where this isn't enough. My particular example was repeated pairs of
                              side-by-side <div>s, one containing an image and the other some
                              annotation. It's important that each pair starts vertically aligned,
                              but they're of varying heights.

                              (I have examples of these live, but the CSS is a bit "legacy" so I'm
                              not keen on citing them as an example. I might get to upload a "clean"
                              one sometime)

                              Comment

                              Working...