Why can't the

tag contain a

tag inside it?

前端 未结 5 2041
小蘑菇
小蘑菇 2020-11-21 22:09

As far as I know, this is right:

some words

But this is wrong:

&l

5条回答
  •  隐瞒了意图╮
    2020-11-21 23:01

    According to HTML5, the content model of div elements is flow content

    Most elements that are used in the body of documents and applications are categorized as flow content.

    That includes p elements, which can only be used where flow content is expected.

    Therefore, div elements can contain p elements.


    However, the content model of p elements is Phrasing content

    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.

    That doesn't include div elements, which can only be used where flow content is expected.

    Therefore, p elements can't contain div elements.

    Since the end tag of p elements can be omitted when the p element is immediately followed by a div element (among others), the following

    some words

    is parsed as

    some words

    and the last

    is an error.

提交回复
热议问题