什么是不同的doctype在HTML中,它们是什么意思? [英] What are the different doctypes in html and what do they mean?

查看:124
本文介绍了什么是不同的doctype在HTML中,它们是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,有哪些不同的文档类型,它们是什么意思?我注意到当我从

 <!DOCTYPE HTML PUBLIC>  -  // W3C切换时,IE7的布局看起来有点不同// DTD HTML 4.0 Transitional // EN> 

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 

有没有其他的,有什么影响或后果?

感谢!

解决方案

Doctype 文档类型声明文档类型定义 一个XML文档。对于XML和XHTML文档,都有很多DTD。 XML本身没有太多的模式或一套非常特定的规则,除了要求所有东西都是格式良好的。您可以将DTD视为文档的模式

由于标准的移动,大多数现代浏览器实际上有不同的呈现模式(标准模式,用于根据更新的Web标准呈现您的文档和CSS,并且怪异模式,其中浏览器从网络早期阶段带回一些渲染想法)。这些模式是为了向后兼容的目的而设立的。在网络第一个时代创建的网页的广阔风景根据他们的时间规则呈现,而较新的文档可以吸引新的标准浪潮。随着时间的推移和想象出新的格式,可能会创建相应的DTD。



浏览器差异

理想情况下,浏览器加载的页面将读取顶部的Doctype并使用它查找文档类型定义。然后它将使用该DTD的模式作为阅读文档其余部分的基础。然后,Doctypes对于验证标记文档是非常重要的。 DTD将提供您的文档进行验证的标准。



不幸的是,这不是一个理想的世界。浏览器在这里不一定表现一致,如果他们这样做,一致的行为就不符合最初的Doctypes的愿景。虽然解析是独立于Doctype完成的,但主要浏览器至少会检查Doctype以确定呈现模式。如果您的文档类型不存在或不完整,浏览器可能会以怪异模式进行渲染。要使写得很好的现代文档正确显示,浏览器应该以标准模式进行呈现。 Mozilla,Safari和一些最新版本的Opera实际上实现了 几乎标准 模式,它完全专用于过渡页面。



当您更改文档类型并注意页面显示方式的变化时,这是因为浏览器可能在尝试解析文档时应用稍微不同的一组规则。因此,生成的页面可能有点不同,具体取决于它的所有部分是否符合DTD,或者至少取决于浏览器,您的数据在渲染模式下根据DOCTYPE的建议进行验证。 p>

选择Doctype



为符合标准,应使用严格的文档类型只要有可能。



XHTML 中编写时,此Doctype很常见:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // EN
http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd\">

HTML 4.1 中编写代码时, p>

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

为了完整性,这里列出了XHTML和HTML 4的其他常见doctypes:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // EN
http:// www .w3.org / TR / XHTML1 / DTD / XHTML1-strict.dtd>

<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Frameset // EN
http://www.w3.org/TR/xhtml1/DTD/ XHTML1-frameset.dtd>

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

<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Frameset // EN
http://www.w3.org/TR/html4/frameset。 DTD>

严格与过渡文档类型的辩论

标准宣传者呼吁网络开发人员停止在新页面上使用Transitional Doctype,而是使用Strict。再次,这是一个理论和实践有一些困难调和的情况。过渡型Doctype的最初希望是为遗留网站向符合标准的过渡提供一个中途之家。使用过渡型文档类型时,对元素和属性的限制实际上不太严格,因此开发人员可以更快地在标准模式下运行它们的工作,并逐渐淘汰未来的差异。

存在争议,因为开发人员在企业环境中更改Doctype并不总是那么简单。中小型网站的自由职业开发人员和制作人员通常可以更轻松地确定他们的文档类型并进行转换。在高需求的基于Web的服务的企业生产环境中,对遗留系统和第三方代码产品的依赖性本质上更复杂,它们本身可能处于移除或重新设计的路线图上,但是执行这些更改必须是 $ b

有用的工具

W3C( 万维网联盟 )是一个在定义这些类型方面发挥积极作用的组织的标准。他们在 http://validator.w3.org/ 上保留有用的在线工具根据他们的标准验证和验证文件。还有许多其他第三方工具和 浏览器扩展程序 具有类似的功能。


As the title describes, what are the different doctypes available and what do they mean? I notice that the layout looks a little different in IE7 when I switch from

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

to

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Are there any others and what are the effects or ramifications?

Thanks!

解决方案

A Doctype, or Document Type Declaration associates the document with a Document Type Definition.

The Document Type Definition is a standard for an XML document. There are many DTDs, for both XML and XHTML documents. XML itself doesn't have much of a schema or a very specific set of rules, apart from the requirement that everything be well-formed. You can think of a DTD as a more specific schema for the document.

Rendering Modes

Due to the standards movement, most modern browsers actually have different rendering modes (standards mode, for rendering your document and css according to more recent web standards, and quirks mode, wherein the browser brings back some rendering ideas from the early days of the web). These modes are instituted for purposes of backward-compatibility. The vast landscape of web pages which were created in the first era of the web are rendered according to the rules of their time, while newer documents can appeal to the new wave of standards. As time goes on and new formats are imagined, a corresponding DTD could potentially be created.

Browser Discrepancies

In an ideal world, a page that is being loaded by a browser would read the Doctype at the top and use it to look up a Document Type Definition. It would then use the schema of that DTD as the basis for reading the rest of the document. Doctypes, then, would be essential for validating markup documents. The DTD would provide the standard against which your document is to be validated.

Unfortunately, it's not an ideal world. Browsers don't necessarily behave consistently here, and if they do, the consistent behavior isn't quite in line with the original vision for Doctypes. Although parsing is done independently of the Doctype, major browsers will at least examine the Doctype to determine the rendering mode. If your Doctype is absent or is incomplete, the browser will likely be rendering in quirks mode. For well-written, modern documents to appear correctly, the browser should be rendering in standards mode. Mozilla, Safari, and some recent versions of Opera actually implement an Almost Standards mode, which is dedicated entirely to transitional pages.

When you change the Doctype and notice changes in the way a page is displayed, it is because the browser may be applying a slightly different set of rules when it tries to parse the document. As a consequence, the resulting page may be a little bit different, depending on whether all of its parts conform to the DTD, or at least, depending on the browser, that your data validates within the rendering mode that the doctype suggests.

Choosing a Doctype

In pursuit of standards-compliance, strict Doctypes should be used whenever possible.

When writing in XHTML, this Doctype is common:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

When writing in HTML 4.1, this one is common instead:

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

Some other common doctypes for XHTML and HTML 4 are listed here, for completeness:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

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

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

Debate on Strict versus Transitional Doctypes

Standards evangelists have called for web developers to stop using the Transitional Doctype on new pages and instead use Strict. Again, this is a case where the theory and the practice have some difficulties being reconciled. The original hope of the transitional Doctype was to provide a halfway house for transitioning legacy websites toward standards-compliance. With transitional doctypes, the restriction on elements and attributes is literally "less strict", so developers would be able to get their work running under standards mode sooner, and phase out the outstanding differences over time.

Controversy exists because it isn't always quite so simple for a developer change the Doctype in an enterprise environment. Freelance developers and makers of small- or medium- sized websites may often have an easier time determining their Doctype and making this transition. In an enterprise production environment for a highly-demanded web-based service, there are inherently more complicated dependencies on legacy systems and 3rd party code products, which themselves may be on a roadmap for removal or redesign, but the execution of such changes must be done methodically and incrementally.

Helpful Tools

The W3C (World Wide Web Consortium) is a group which plays an active role in defining these kinds of standards. They maintain a helpful online tool at http://validator.w3.org/ for verifying and validating documents against their standards. There are many other 3rd party tools and browser extensions with similar functionality.

这篇关于什么是不同的doctype在HTML中,它们是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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