paragraph tag not closed?

后端 未结 2 1703
醉话见心
醉话见心 2021-01-22 11:34

I simplified my html code down to this



Who are

相关标签:
2条回答
  • 2021-01-22 11:39

    The meaning of that error message is that the p#whoarewe element was already implicitly closed when the HTML processor encountered the h2 element, so the </p> end tag at that particular point seems gratuitous because there is no open p element for the end tag to close.

    So no, your computer is not glitching out. The markup is indeed malformed.

    Depending on what you are trying to accomplish, #whoarewe looks like it should be its own div element or a sectioning element, rather than a p. A paragraph cannot contain a heading; they are two thematically separate structures and cannot exist within the other.

    0 讨论(0)
  • 2021-01-22 11:54

    There's a fixed set of elements, belonging to Phrasing content category, that can be children of <p> element:

    Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

    a abbr area (if it is a descendant of a map element) audio b bdi bdo br button 
    canvas cite code data datalist del dfn em embed i iframe img input ins
    kbd keygen label map mark math meter noscript object output 
    progress q ruby s samp script select small span strong sub sup svg
    template textarea time u var video wbr Text
    

    <h2> element, as many other block-level ones, doesn't belong here. In this case, <p> element closes automatically. Quoting the docs:

    A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, nav, ol, p, pre, section, table, or ul, element, or if there is no more content in the parent element and the parent element is not an a element.

    In this particular case, the structure of DOM is as follows:

    <p id="whoarewe"></p>
    <h2>Who are we?</h2>
    wersfgse
    </p>
    

    ... and, as you can see, the end tag isn't really welcome. Actually, you should be grateful for Firefox DOM Inspector marking this error. )

    0 讨论(0)
提交回复
热议问题