vs

前端 未结 5 2071
独厮守ぢ
独厮守ぢ 2020-12-18 22:37

I am trying to understand why is there a difference in how a browser displays

verses
?

Here is an example: The expected

5条回答
  •  悲哀的现实
    2020-12-18 23:11

    As you have clarified that you're using HTML5... from the HTML5 spec:

    Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

    The void elements are:

    area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

    The foreign elements are those from the MathML and SVG namespaces. As you can see, none of these elements are the div element, and therefore your second example is invalid HTML5.

提交回复
热议问题