HTML问题:先关闭父元素再关闭子节点可以吗?
HTML issue: Is it okay if I close a parent element and then a child node?
我想知道 HTML5 是否允许您像这样混合标签:
<u>hello <i>wor</u>ld</i>
虽然它在最流行的浏览器的最新版本中似乎可以正常工作,但我想知道是否可以在我的网页上使用它。
我知道它 与 DOM 不兼容。正因如此,浏览器是这样解析的:
<u>hello </u><i><u>worl</u>ld</i>
所以这些是我的问题:
- What does the HTML5 specification say about this? And the HTML4.01 spec?
- Is this a good practice? (or not so bad at least)
- Are there any differences among browsers? (Is this cross-browser-compatible?)
不行,不行。
HTML - 任何版本 - 期望 well-formedness,维基百科这样定义(强调我的):
In web page design, and generally for all markup languages such as
SGML, HTML, and XML, a well-formed element is one that is either
- opened and subsequently closed,
- an empty element, which in that case must be terminated,
- properly nested so that it does not overlap.
您的浏览器可能会接受它并尝试解决它,但根据标准它是不行的。
当使用 W3 验证器根据 HTML5 规范验证您的 html 时,出现以下错误。
根据 HTML 4.01 规范进行验证时,出现以下错误。
我找到了它们!它们被称为错误嵌套的内联标签。这是 HTML5 规范的 link:http://www.w3.org/TR/html5/syntax.html#misnested-tags:-b-i-/b-/i
我想知道 HTML5 是否允许您像这样混合标签:
<u>hello <i>wor</u>ld</i>
虽然它在最流行的浏览器的最新版本中似乎可以正常工作,但我想知道是否可以在我的网页上使用它。
我知道它 与 DOM 不兼容。正因如此,浏览器是这样解析的:
<u>hello </u><i><u>worl</u>ld</i>
所以这些是我的问题:
- What does the HTML5 specification say about this? And the HTML4.01 spec?
- Is this a good practice? (or not so bad at least)
- Are there any differences among browsers? (Is this cross-browser-compatible?)
不行,不行。
HTML - 任何版本 - 期望 well-formedness,维基百科这样定义(强调我的):
In web page design, and generally for all markup languages such as SGML, HTML, and XML, a well-formed element is one that is either
- opened and subsequently closed,
- an empty element, which in that case must be terminated,
- properly nested so that it does not overlap.
您的浏览器可能会接受它并尝试解决它,但根据标准它是不行的。
当使用 W3 验证器根据 HTML5 规范验证您的 html 时,出现以下错误。
根据 HTML 4.01 规范进行验证时,出现以下错误。
我找到了它们!它们被称为错误嵌套的内联标签。这是 HTML5 规范的 link:http://www.w3.org/TR/html5/syntax.html#misnested-tags:-b-i-/b-/i