`

HTML doctype

阅读更多

1.doctype的概念?

html的doctype声明需要放在html的最开始,doctype的解释请参考“HTML <!DOCTYPE> 标签”。

2.为什么要用doctype?

doctype出现的目的是为了让浏览器知道是用“怪异模式(Quirks Mode)”还是“标准/严格模式(Standards Mode)”渲染html。实际上除了“怪异模式”和“严格模式”在其他浏览器中还有一种“类严格模式(Almost Standards Mode)”。各个浏览器会根据doctype的不同值开启不同的模式。详细信息可以参考“Activating Browser Modes with Doctype”。

之所以出现不同模式的原因是在IE和Netscape 兼容W3C标准之前,对CSS的实现有很大的差异,在IE和Netscape向W3C标准靠拢后,为了向前兼容,就出现了不同的模式。可以让web开发人员选择使用哪种模式作为标准。

不同的模式会影响浏览器在CSS布局、CSS解析和脚本(Script)这3方面产生的行为。

3.doctype该怎么写?

HTML5不在基于SGML,所以强烈建议将html的doctype声明为:“<!DOCTYPE html>”。这会让浏览器开启标准/严格模式。

4.doctype嗅探(doctype sniffing)

Doctype sniffing only applies to documents served as text/html. Documents sent as XML always activate the Standards layout mode. This includes documents sent as application/xhtml+xml. The consequence is that XHTML 1.0 Transitional documents are rendered in the Almost Standards mode when served as text/html under pretext of the Appendix C but in the Standards Mode when served asapplication/xhtml+xml.

5.HTML不再基于SGML?

The HTML5 standard specifies two serializations of HTML5: "html" and "xml". "xml" is a valid XML serialization (which in turn is a subset of SGML). "html" is not based on any specific serialization standard anymore, it has its own complete serialization. Herein lies the difference: HTML4 has a "sgml" serialization and "xml" serialization (called XHTML 1.0)

Of course HTML5 is for a large part based on HTML4, which is based on SGML and XHTML, which is based on HTML4 and XML.

Also see the history section of the HTML5 specification

 

参考:

TML <!DOCTYPE> 标签:

http://www.w3school.com.cn/tags/tag_doctype.aspa

为什么使用<!DOCTYPE HTML>:

“http://i.wanz.im/2010/05/28/why_doctype_html/”

Activating Browser Modes with Doctype:

https://hsivonen.fi/doctype/

HTML,XML,XHTML,HTML5和SGML简介:

http://lastplace.diandian.com/2012-10-04/sgml-the-sons

Quirks mode and strict mode:

http://www.quirksmode.org/css/quirksmode.html#link1

什么是“怪异模式”,什么是“标准模式”:

https://developer.mozilla.org/zh-CN/docs/Mozilla_Web_Developer_FAQ

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics