“<!DOCTYPE html>”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9346954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"<!DOCTYPE html>" What does it mean?
提问by zono
I use a fantastic javascript organization tree generator named "ECOTree" but the drawing does not work when I put <!DOCTYPE html>
. Labels in the boxes are not put in the boxes correctly.
我使用了一个很棒的 javascript 组织树生成器,名为“ECOTree”,但是当我把<!DOCTYPE html>
. 盒子中的标签未正确放入盒子中。
You can see the error at sample1.htm on the site below. Could anybody suggest me how to fix. http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=16192
您可以在以下站点的 sample1.htm 中看到错误。任何人都可以建议我如何修复。 http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=16192
(In order to follow my project rule, I have to define <!DOCTYPE html>
)
(为了遵循我的项目规则,我必须定义<!DOCTYPE html>
)
回答by rockerest
<!DOCTYPE html>
is the explicit Document Type Declaration.
<!DOCTYPE html>
是显式的Document Type Declaration。
From the linked page:
从链接页面:
The DOCTYPE Declaration (DTD or Document Type Declaration) does a couple of things:
- When performing HTML validation testing on a web page it tells the HTML (HyperText Markup Language) validator which version of (X)HTML standard the web page coding is supposed to comply with. When you validate your web page the HTML validator checks the coding against the applicable standard then reports which portions of the coding do not pass HTML validation (are not compliant).
- It tells the browser how to render the page in standards compliant mode.
DOCTYPE 声明(DTD 或文档类型声明)做了几件事:
- 在网页上执行 HTML 验证测试时,它会告诉 HTML(超文本标记语言)验证器网页编码应该符合哪个版本的 (X)HTML 标准。当您验证网页时,HTML 验证器会根据适用的标准检查编码,然后报告编码的哪些部分未通过 HTML 验证(不合规)。
- 它告诉浏览器如何以符合标准的模式呈现页面。
#2 is a very important reason for using it.
#2 是使用它的一个非常重要的原因。
<!DOCTYPE html>
, specifically, is the correct declaration for HTML5, and should be used pretty much from here to the near future. You can still use legacy strings or obsolete permitted strings, but the previously written format is all that is required in HTML5. On a further note, this DTD will cause all modern browsers dead linkto switch to their standards (compliance) mode, even if they don't support HTML5.
<!DOCTYPE html>
,具体来说,是HTML5的正确声明,从现在到不久的将来都应该使用。您仍然可以使用旧字符串或过时的允许字符串,但以前编写的格式是 HTML5 中所需的全部内容。在进一步的说明,这个DTD会导致所有现代浏览器都死链接,以切换到他们的标准(达标)模式,即使他们不支持HTML5。
Here's some more info:
以下是更多信息:
Activating Browser Modes with Doctype& Choosing a Doctype (same page)
World Wide Web Consortium(they make web standards)
激活浏览器模式与文档类型和选择DOCTYPE(同一页)
万维网联盟(他们让Web标准)
回答by Alohci
<!DOCTYPE html>
is nota "Document Type Declaration".
<!DOCTYPE html>
是不是一个“文档类型声明”。
A "Document Type Declaration" is an SGML concept for signalling the mark-up syntax and vocabulary for the mark-up that follows. <!DOCTYPE html>
does not conform to the requirements of that. This is unlike <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
which is a SGML conforming Document Type Declaration.
“文档类型声明”是一个 SGML 概念,用于用信号通知后面的标记的标记语法和词汇。<!DOCTYPE html>
不符合那个要求。这与<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
符合 SGML 的文档类型声明不同。
<!DOCTYPE html>
does notindicate an HTML5 document.
<!DOCTYPE html>
并不能表明一个HTML5文档。
Although HTML5 conforming documents in the text/html serialization are required to have <!DOCTYPE html>
at their start, it does not follow that the converse is true. I.e. a document can have <!DOCTYPE html>
at its start and not be an HTML5 document. For example, it is intended that all future versions of HTML will use the same character sequence at their start. So it might indicate an HTML5 document, or an HTML6, HTML7 etc. document, an HTML5+RDFa-lite document, or a document from an entirely competing standard.
尽管 text/html 序列化中符合 HTML5 的文档需要<!DOCTYPE html>
在其开始时具有,但这并不意味着反过来就是真的。即一个文档可以<!DOCTYPE html>
在它的开始而不是一个 HTML5 文档。例如,所有未来版本的 HTML 都打算在开始时使用相同的字符序列。因此,它可能表示 HTML5 文档,或 HTML6、HTML7 等文档、HTML5+RDFa-lite 文档或来自完全竞争标准的文档。
The HTML5 spec describes <!DOCTYPE html>
as "a required preamble", and that's much closer to the mark.
HTML5 规范将其描述<!DOCTYPE html>
为“必需的序言”,这更接近于标记。
It's just the shortest character sequence that will request to legacy as well as future browsers that the browser should handle the HTML of the document using its most modern HTML processing mode. It was chosen as the conforming preamble for HTML5 for solely that reason.
它只是最短的字符序列,它将向旧版和未来的浏览器请求浏览器应使用其最现代的 HTML 处理模式来处理文档的 HTML。正是因为这个原因,它被选为符合 HTML5 的序言。
If it can be said to have any meaning at all, it is that it indicates that the document was created or last refactored around about 2007 or later. Again, the converse does not necessarily apply. A document not containing <!DOCTYPE html>
does not imply that the document was created before any particular date.
如果可以说它有任何意义,那就是它表明该文档是在 2007 年左右或之后创建或最后一次重构的。同样,反过来不一定适用。不包含<!DOCTYPE html>
的文档并不意味着该文档是在任何特定日期之前创建的。
回答by defau1t
“<!DOCTYPE html>” What does it mean?
“<!DOCTYPE html>”是什么意思?
It means that your webpage will be rendered as per html5 standards, obviously you if you have something that browser doesn't support then you need to use a polyfill for that.
这意味着您的网页将按照 html5 标准呈现,显然,如果您有浏览器不支持的内容,那么您需要为此使用 polyfill。
回答by Hema bhandari
It tells the version i.e the page is written in HTML5. Basically it is the instruction to the web browser about what version of HTML the page is written in and even tell web browser how to render the page.
它告诉版本,即页面是用 HTML5 编写的。基本上,它是向 Web 浏览器指示页面是用什么版本的 HTML 编写的,甚至告诉 Web 浏览器如何呈现页面。
Following are list of HTML Doctype Declarations List:
以下是 HTML Doctype 声明列表:
回答by tutu
? The term?DOCTYPE?tells the browser which type of HTML is used on a webpage. In turn, the browsers use?DOCTYPE?to determine how to render a page. Failing to use?DOCTYPE?or using a wrong?DOCTYPE may load your page in Quirks Mode. See example:
? 术语“DOCTYPE”告诉浏览器在网页上使用哪种类型的 HTML。反过来,浏览器使用?DOCTYPE?来确定如何呈现页面。未使用?DOCTYPE?或使用错误?DOCTYPE 可能会在 Quirks 模式下加载您的页面。见示例:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">.