DOCTYPE有什么意义?

编程入门 行业动态 更新时间:2024-10-17 18:30:05
本文介绍了DOCTYPE有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道不同的文档类型基本上是关于html是如何符合的,但是它与您指定的文档类型有什么不同?浏览器根据文档类型处理相同的代码吗? 谢谢

更新 - 大多数答案提到如果没有指定文档类型,怪癖模式可以被关闭。但是,xhtml和html 4.01会有什么不同呢?

解决方案

最重要的是拥有一个doctype或不是。如果你不这样做,浏览器将以怪癖模式而不是标准模式工作,许多事情会稍有不同。如果您有一个—任何—通常会在浏览器中激活更多符合标准的行为。 这篇文章了解doctypes在各种不同浏览器上所做的操作以及使用什么模式—怪癖,标准,几乎标准等。—不同的浏览器有。引用相关部分:

text / html内容模式

文本/ html内容的模式选择取决于doctype嗅探(本文稍后讨论)。在IE8和 IE9中,模式也取决于其他因素。但是,默认情况下,即使在 IE8和IE9中,该模式也取决于非内部网站的 doctype,即不在由 Microsoft提供的黑名单中。

不能强调就足够了,模式的确切行为因浏览器而异, b $ b文档已经统一。 $ b 古怪模式

在Quirks模式下,浏览器违反了当前的Web 格式规范,以便避免根据在后期普遍存在的惯例创作的破坏页面20世纪90年代。不同的浏览器实现不同的怪癖。 在Internet Explorer 6,7,8和9 中,Quirks模式被有效冻结 IE 5.5。在其他浏览器中,Quirks 模式与几乎标准模式下的有一些偏差。

如果您正在编写新页面,则您应该遵守的相关规范(特别是b $ b中的CSS 2.1),并使用标准模式。

标准模式 在标准模式中,浏览器尝试给出符合规范的文档, $ b在特定浏览器中实现的正确对待。

因为不同的浏览器处于不同阶段的合规性,所以标准模式不是单一目标,也就是。

HTML 5将此模式称为无怪癖模式。

几乎标准模式

Firefox,Safari, Chrome,Opera 7.5),IE8和IE9 也有一种称为the Almost的模式标准模式,它根据CSS2规范传统地执行纵向大小的表格单元格,而不是严格地执行。 Mac IE 5,Windows IE 6和7,7.5之前的Opera 和Konqueror不需要几乎标准模式,因为它们没有实现垂直大小的调整表单元严格根据 CSS $规范在各自的标准模式中。在的事实中,它们的标准模式在近乎标准模式下更接近,而不是新标准模式的。

HTML 5称此模式为有限的怪癖模式。

IE7模式 IE8和IE9有一种模式,主要是模式的冻结副本,它是IE7中的标准模式。 其他浏览器没有像这样的模式,并且这种模式没有被HTML5指定为。

IE8标准模式

IE9有一个模式,主要是模式的冻结副本,即IE8中的标准模式。 其他浏览器没有像这样的模式,并且这种模式没有被HTML5指定为。

IE8几乎标准模式

IE9有一个模式,主要是的冻结副本,模式是几乎标准$ b IE8中的$ b模式。其他浏览器不有这样的模式,这种模式不是HTML5指定的。

...但请参阅文章进行全面讨论。

I know that different doctypes are essentially about how compliant the html is, but what difference does it make what doctype you specify? Do browsers handle the same code differently depending on the doctype? Thanks

UPDATE - most answers mention quirks mode can be set off if no doctype is specified. But what would be the different between xhtml and html 4.01?

解决方案

The biggest thing is having a doctype or not. If you don't, the browser will work in a "quirks" mode rather than standards mode and many things will be slightly different. If you have one— any— that typically activates more standards-compliant behavior in the browser.

See this article for the details of what doctypes do on various different browsers and what modes— quirks, standards, almost-standards, etc.— different browsers have. Quoting a relevant section:

Modes for text/html Content

The choice of the mode for text/html content depends on doctype sniffing (discussed later in this document). In IE8 and IE9, the mode also depends on other factors. However, by default even in IE8 and IE9, the mode depends on the doctype for non-intranet sites that are not on a blacklist supplied by Microsoft.

It cannot be stressed enough that the exact behavior of the modes varies from browser to browser even though discussion in this document has been unified.

Quirks Mode

In the Quirks mode the browsers violate contemporary Web format specifications in order to avoid "breaking" pages authored according to practices that were prevalent in the late 1990s. Different browsers implement different quirks. In Internet Explorer 6, 7, 8 and 9, the Quirks mode is effectively frozen IE 5.5. In other browsers, the Quirks mode is a handful of deviations from the Almost Standards mode.

If you are authoring new pages now, you are supposed to comply with the relevant specifications (CSS 2.1 in particular) and use the Standards mode.

Standards Mode

In the Standards mode the browsers try to give conforming documents the specification-wise correct treatment to the extent implemented in a particular browser.

Since different browsers are at different stages of compliance, the Standards mode isn’t a single target, either.

HTML 5 calls this mode the "no quirks mode".

Almost Standards Mode

Firefox, Safari, Chrome, Opera (since 7.5), IE8 and IE9 also have a mode known as "the Almost Standards mode", which implements the vertical sizing of table cells traditionally and not rigorously according to the CSS2 specification. Mac IE 5, Windows IE 6 and 7, Opera prior to 7.5 and Konqueror do not need an Almost Standards mode, because they don’t implement the vertical sizing of table cells rigorously according to the CSS2 specification in their respective Standards modes anyway. In fact, their Standards modes are closer to the Almost Standards mode than to the Standards mode of newer browsers.

HTML 5 calls this mode the "limited quirks mode".

IE7 Mode

IE8 and IE9 have a mode that is mostly a frozen copy of the mode that was the Standards mode in IE7. Other browsers do not have a mode like this, and this mode is not specified by HTML5.

IE8 Standards Mode

IE9 has a mode that is mostly a frozen copy of the mode that was the Standards mode in IE8. Other browsers do not have a mode like this, and this mode is not specified by HTML5.

IE8 Almost Standards Mode

IE9 has a mode that is mostly a frozen copy of the mode that was the Almost Standards mode in IE8. Other browsers do not have a mode like this, and this mode is not specified by HTML5.

...but see the article for a full discussion.

更多推荐

DOCTYPE有什么意义?

本文发布于:2023-11-02 16:53:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么意义   DOCTYPE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!