为什么我需要一个文档类型? (它有什么作用) [英] Why do I need a doctype? (What does it do)
问题描述
可能存在重复:
HTML:!DOCTYPE的功能是什么
我最近在这里问过一个问题,解决方案很简单:
您需要在页面中添加一个doctype。这应该解决您的问题。
现在,我的网页在没有文档类型(IE除外)的每个浏览器中都能正常工作。 IE是否需要一个doctype(这是一个IE浏览器),其他浏览器只是假设它 OR ,或者它正在做我没有看到的东西。
它的功能是什么,它是如何工作的?
所有浏览器都需要DOCTYPE。如果没有 DOCTYPE
,您将迫使浏览器以怪癖模式呈现。
但是, 2.2。 DOCTYPE HTML5的HTML语法要求指定DOCTYPE以确保浏览器以标准模式呈现页面。 DOCTYPE没有其他用途,因此对于XML是可选的。具有XML媒体类型的文档始终在标准模式下处理。 [DOCTYPE] DOCTYPE声明是 DOCTYPE
简化为:
<!DOCTYPE html>
< blockquote>
<!DOCTYPE html>
,并且在HTML语法中不区分大小写。早期版本的HTML中的DOCTYPE较长,因为HTML语言是基于SGML的,因此需要对DTD进行引用。对于HTML5,这不再是这种情况,只需要DOCTYPE为使用HTML语法编写的文档启用标准模式。浏览器已经为<!DOCTYPE html>
执行此操作。
Possible Duplicate:
HTML: What is the functionality of !DOCTYPE
I recently asked a question here and the solution was a simple:
You need to add a doctype to the page. This should fix the issue for you.
Now, my pages work fine in every browser without the doctype (except IE). Does IE need a doctype (is this an IE only thing) and do other browsers just assume it OR or is it doing something I'm not seeing.
What are its functions and how does it work?
All browsers need the doctype. Without the DOCTYPE
you are forcing the browsers to render in Quirks Mode.
However, DOCTYPE
was only partially used by the browsers in determining dialect and parsing, even though that was the purpose. This is why HTML5 has reduced the DOCTYPE
to simply:
<!DOCTYPE html>
2.2. The DOCTYPE
The HTML syntax of HTML5 requires a DOCTYPE to be specified to ensure that the browser renders the page in standards mode. The DOCTYPE has no other purpose and is therefore optional for XML. Documents with an XML media type are always handled in standards mode. [DOCTYPE]
The DOCTYPE declaration is
<!DOCTYPE html>
and is case-insensitive in the HTML syntax. DOCTYPEs from earlier versions of HTML were longer because the HTML language was SGML-based and therefore required a reference to a DTD. With HTML5 this is no longer the case and the DOCTYPE is only needed to enable standards mode for documents written using the HTML syntax. Browsers already do this for<!DOCTYPE html>
.
Source: HTML5 differences from HTML4: DOCTYPE
这篇关于为什么我需要一个文档类型? (它有什么作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!