HTML5不基于SGML,因此不需要引用DTD [英] HTML5 is not based on SGML, and therefore does not require a reference to a DTD

查看:655
本文介绍了HTML5不基于SGML,因此不需要引用DTD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自: http://www.w3schools.com/tags/tag_doctype.asp


< !DOCTYPE>声明不是HTML标记;它是向web浏览器
发送关于写入页面的HTML版本的指令。

在HTML 4.01中,< !DOCTYPE>声明引用DTD,因为HTML
4.01基于SGML。 DTD指定了标记语言的规则,以便浏览器正确地呈现内容。

HTML5不基于SGML,因此确实不需要参考
到DTD。
b
$ b

提示:总是添加< !DOCTYPE>声明,以便浏览器知道期望的文档类型。

大胆的声明意味着当我们使用HTML 5时,我们不需要指定< !DOCTYPE html>

该声明究竟意味着什么?



我目前使用< !DOCTYPE html> 在浏览器Firefox 4的HTML文件中。我删除了该声明,但在渲染的输出中没有看到任何区别。 这是否意味着问题可能发生在旧浏览器而不是新浏览器中? / div>

术语很混乱,但是 DTD(文档类型定义只是文档类型声明 的一部分(通常缩写为doctype)。如果您使用HTML5,则应始终包含doctype 声明<!DOCTYPE html> ),但文档类型 definition < 为了提供一个具体的例子,这就是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 // ENhttp://www.w3 .org / TR / html4 / strict.dtd

这是HTML5的一部分。 PUBLIC指定了DTD的可用性,所以如果没有DTD,也不应该包含它。


From: http://www.w3schools.com/tags/tag_doctype.asp

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

In HTML 4.01, the < !DOCTYPE > declaration refers to a DTD, because HTML 4.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 reference to a DTD.

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

Does the bold statement mean that when we are using HTML 5 we don't need to specify < !DOCTYPE html >?
What does that statement exactly mean?

I am currently using < !DOCTYPE html > in my html file with the browser Firefox 4. I removed that declaration but did not see any difference in the rendered output. Does it mean that the problem may occur in old browsers and not in new ones?

解决方案

The terminology is confusing, but a DTD (document type definition) is only one part of a document type declaration (usually shortened to "doctype"). You should always include a doctype declaration (<!DOCTYPE html> if you use HTML5), but a document type definition identifier is no longer necessary.

To provide a concrete example, this is what a HTML4.01 document type declaration ("doctype") might have looked like:

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

The document type definition ("DTD") identifier in the above declaration is this part:

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

That's the part you can leave off for HTML5. "PUBLIC" specifies the DTD's availability, so that should also not be included if there is no DTD.

这篇关于HTML5不基于SGML,因此不需要引用DTD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆