简体   繁体   English

为什么 XHTML 标签在 HTML5 文档中有效,反之亦然?

[英]Why do XHTML tags work in HTML5 documents and vice versa?

According to this document there are some XHTML tags, that are not supported in new HTML5 standard, for example big and strike .根据本文档,有一些XHTML标签在新的HTML5标准中不受支持,例如bigstrike However when I declare my html document as HTML5 they still work for some reason, consider this example:但是,当我将我的 html 文档声明为HTML5时,由于某种原因它们仍然有效,请考虑以下示例:

<!DOCTYPE html /> <!-- HTML5 decalration -->
<html>
    <head>
    </head>
    <body>
        <!-- These tags should not work, because the document is declared as HTML5, but they still work -->
        <big>Hello</big>
        <strike>123</strike>
    </body>
</html>

Same applies vice versa, there many other HTML5 tags that are not supported in XHTML standard, for example svg tag, however when I declare my document as XHTML they still work.反之亦然, XHTML标准不支持许多其他HTML5标记,例如svg标记,但是当我将文档声明为XHTML时,它们仍然有效。 Consider this example:考虑这个例子:

<!-- XHTML declaration -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
<html>
    <head>
    </head>
    <body>
        <!-- Should not work because SVG are not supported in XHTML standard -->
        <svg width="100" height="100">
            <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
        </svg>
    </body>
</html>

The browser I used is the current version of Google Chrome .我使用的浏览器是当前版本的Google Chrome Can anyone explain why this is happening?谁能解释为什么会这样? What is the point of declaring the document as HTML5 or XHTML if the browsers will support both regardless of DOCTYPE specified?如果浏览器无论指定DOCTYPE都支持两者,那么将文档声明为HTML5XHTML有什么意义?

In the first example:在第一个示例中:

These are so-called deprecated tags that you can still use in HTML5, but they're not recommended.这些是所谓的弃用标签,您仍然可以在 HTML5 中使用它们,但不推荐使用它们。 They could be removed any time by browsers (although this is pretty unlucky).它们可以随时被浏览器删除(尽管这很不走运)。

The second example:第二个例子:

Most browsers like Google Chrome or Firefox don't render XHTML as XHTML.大多数浏览器(如 Google Chrome 或 Firefox)不会将 XHTML 呈现为 XHTML。 They actually render it in HTML5.他们实际上在 HTML5 中渲染它。 The things that are different in XHTML are converted to HTML5 using a preprocessor. XHTML 中的不同之处使用预处理器转换为 HTML5。 Because SVG isn't part of XHTML standard, it won't be converted but just stays as it is, and thus displayed like in HTML5.因为 SVG 不是 XHTML 标准的一部分,所以它不会被转换,而是保持原样,因此像 HTML5 一样显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM