gpt4 book ai didi

HTML5 不基于 SGML,因此不需要引用 DTD

转载 作者:搜寻专家 更新时间:2023-10-31 02:26:07 32 4
gpt4 key购买 nike

发件人:http://www.w3schools.com/tags/tag_doctype.asp

The < !DOCTYPE > declaration is not an HTML tag; it is an instruction tothe web browser about what version of HTML the page is written in.

In HTML 4.01, the < !DOCTYPE > declaration refers to a DTD, because HTML4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.

HTML5 is not based on SGML, and therefore does not require a referenceto a DTD.

Tip: Always add the < !DOCTYPE > declaration to your HTML documents, so that the browser knows what type of document to expect.

加粗的语句是否意味着我们在使用 HTML 5 时不需要指定 < !DOCTYPE html >
该声明的确切含义是什么?

我目前使用浏览器 Firefox 4 在我的 html 文件中使用 < !DOCTYPE html >。我删除了该声明,但在呈现的输出中没有看到任何差异。 是不是说这个问题可能出现在旧的浏览器上,而不是新的?

最佳答案

术语令人困惑,但是 DTD (document type definition)只是 document type declaration 的一部分(通常缩写为“doctype”)。您应该始终包含文档类型声明(如果您使用 HTML5,则为 <!DOCTYPE html>),但不再需要文档类型定义标识符。

举一个具体的例子,这是 HTML4.01 文档类型声明(“doctype”)的样子:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

上述声明中的文档类型定义("DTD")标识符是这部分:

"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"

对于 HTML5,您可以省略这一部分。 “PUBLIC”指定 DTD 的可用性,因此如果没有 DTD,也不应包括在内。

关于HTML5 不基于 SGML,因此不需要引用 DTD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16184832/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com