Html 什么是怪癖模式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1695787/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:13:50  来源:igfitidea点击:

What is quirks mode?

htmlcss

提问by Ibrahim AbuRajab

In a lot of articles about design, quirks mode is mentioned. Anybody have an idea about this thing in plain text and in a development prospective?

在很多关于设计的文章中,都提到了 quirks 模式。任何人都对纯文本和发展前景有关于这件事的想法?

采纳答案by Haim Evgi

you can read in this links :

您可以在此链接中阅读:

http://en.wikipedia.org/wiki/Quirks_mode

http://en.wikipedia.org/wiki/Quirks_mode

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

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

http://www.cs.tut.fi/~jkorpela/quirks-mode.html

http://www.cs.tut.fi/~jkorpela/quirks-mode.html

Modern browsers generally try to render HTML content according to the W3C recommendations. However, to provide compatibility with older web pages, and to provide additional "intuitive" functionality, all browsers support an alternative "quirks mode".

Quirks mode is not, however, a standard. The rendering of any page in quirks mode in different browsers may be different. Whenever possible, it is better to adhere to the W3C standards and try and avoid depending on any past or present browser quirks.

Generally, quirks mode is turned on when there is no correct DOCTYPE declaration, and turned off when there is a DOCTYPE definition. However, invalid HTML - with respect to the chosen DOCTYPE - can also cause the browser to switch to quirks mode.

More information on the different quirks modes in different browsers can be found at QuirksMode.org

现代浏览器通常尝试根据 W3C 建议呈现 HTML 内容。然而,为了提供与旧网页的兼容性,并提供额外的“直观”功能,所有浏览器都支持另一种“怪癖模式”。

然而,怪癖模式不是标准。在不同浏览器中以 quirks 模式呈现的任何页面可能会有所不同。只要有可能,最好遵守 W3C 标准并尽量避免依赖任何过去或现在的浏览器怪癖。

通常,在没有正确的 DOCTYPE 声明时开启 quirks 模式,并在有 DOCTYPE 定义时关闭。但是,无效的 HTML - 相对于所选的 DOCTYPE - 也可能导致浏览器切换到 quirks 模式。

有关不同浏览器中不同怪癖模式的更多信息,请访问QuirksMode.org

回答by Sam152

Quirks mode means your page is running without a document type declared, the document type is defined at the very top of a page and it denotes how the browser should read the HTML. This is StackOverflows doctype:

Quirks 模式意味着您的页面在没有声明文档类型的情况下运行,文档类型定义在页面的最顶部,它表示浏览器应该如何读取 HTML。这是 StackOverflows 文档类型:

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

w3.org specifies web standards and document types, because Stack Overflow uses this doctype it must adhere to the specificationof that doctype.

w3.org 指定了 web 标准和文档类型,因为 Stack Overflow 使用这个 doctype 它必须遵守该 doctype 的规范

This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.

这是 HTML 4.01 Strict DTD,它排除了 W3C 期望随着对样式表支持的成熟而逐步淘汰的表示属性和元素。如果可能,作者应该使用 Strict DTD,但在需要支持表示属性和元素时可以使用 Transitional DTD。

回答by user6712071

Quirks mode also known as Compatibility Mode - means your page is running without a document type declared(this is old school, so this is most likely not needed anymore) The whole point of quirks mode is that it's a compatibility mode for IE5. This means that in addition to changing the layout mode, it also switches off most of the browser features that have been invented since IE5. In quirks mode, the web browser attempts to render/make code based on a ‘best-guess', this includes a generous interpretation of code that may be non-standard or poorly-formed. if you don't declare a doctype, the browser will have to guess what version of HTML/CSS you're running Quirks mode enables older HTML documents to still ‘work its a technique used by web browsers to maintain backward compatibility with older webpages.

Quirks 模式也称为兼容模式 - 意味着您的页面在没有声明文档类型的情况下运行(这是老派,因此很可能不再需要) quirks 模式的全部意义在于它是 IE5 的兼容模式。这意味着除了更改布局模式之外,它还关闭了自 IE5 以来发明的大多数浏览器功能。在 quirks 模式下,Web 浏览器尝试根据“最佳猜测”来呈现/制作代码,这包括对可能是非标准或格式不佳的代码的大量解释。如果您不声明 doctype,浏览器将不得不猜测您正在运行的 HTML/CSS 版本。

if you write a correct doctype, that will trigger standard mode and not Quirks mode older browsers like Netscape 4, are permanently locked in quirks mode

如果您编写了正确的文档类型,将触发标准模式而不是 Quirks 模式 Netscape 4 等旧浏览器将永久锁定在 quirks 模式

Quirks mode enables your browser to behave as if it is an older browser

Quirks 模式使您的浏览器能够像旧浏览器一样运行

It's a mode in which the browser is not law-abiding. It accepts any malformed mark-up in this mode and is not strict with syntax, tags and elements basically means it'll accept your code even if its not-correctly written

这是浏览器不守法的一种模式。它在这种模式下接受任何格式错误的标记,并且对语法、标签和元素不严格,基本上意味着它会接受你的代码,即使它的编写不正确

In quirks mode, browsers behave as they did in the early days of the web. This was done to prevent old sites from breaking too much in new browsers.

在 quirks 模式下,浏览器的行为与 Web 早期一样。这样做是为了防止旧网站在新浏览器中破坏太多。

there is a difficulty in writing a page that looks the same in all browsers. In point of fact, that's impossible. Many browsers were written with special features that only they could handle. Or they have special ways of handling things that are different from how other browsers handle them Using a non-standard will cause every browser to run in quirks mode. But not all browsers behave the same in quirks mode, each browser reverts to its own unique rendering engine which is why it's very difficult to get a page looking alike in different browsers.

编写一个在所有浏览器中看起来都相同的页面是很困难的。事实上,这是不可能的。许多浏览器都编写有只有它们才能处理的特殊功能。或者他们有特殊的处理方式,与其他浏览器处理它们的方式不同。使用非标准将导致每个浏览器都以怪癖模式运行。但并非所有浏览器在 quirks 模式下的行为都相同,每个浏览器都会恢复到自己独特的渲染引擎,这就是为什么很难在不同的浏览器中获得相同页面的原因。

also all your html5 css won't work because it won't be compatible

您所有的 html5 css 也将无法使用,因为它不兼容

Quirks mode supports the JavaScript functionality of IE6, It is similar to the behavior of IE5 and the Quirks mode behavior of IE6, IE7 and IE8.

Quirks 模式支持 IE6 的 JavaScript 功能,它类似于 IE5 的行为以及 IE6、IE7 和 IE8 的 Quirks 模式行为。

in quirks mode, document.body (the body-element) is the root element and in standard mode it's the html-element (document.documentElement). quirks mode is for the old rules of browsers, they made it so that old websites that were written before the world wide web came and before HTML5 was invented don't break. so quirks mode is just to support those websites that had incorrect CSS features. so now developers had a choice. go with standard (todays browsers) or quirks mode for older browsers and websites. in quirks mode a lot of CSS/HTML features that we have today don't work correctly.

在 quirks 模式下,document.body(body 元素)是根元素,而在标准模式下它是 html 元素(document.documentElement)。quirks 模式适用于浏览器的旧规则,它们使在万维网出现和 HTML5 发明之前编写的旧网站不会被破坏。所以 quirks 模式只是为了支持那些 CSS 功能不正确的网站。所以现在开发商有了选择。为旧浏览器和网站使用标准(今天的浏览器)或怪癖模式。在怪癖模式下,我们今天拥有的许多 CSS/HTML 功能无法正常工作。

回答by tom

In past days when web browsers did not have full/correct implementations of CSS, developers relied on these idiosyncrasies to make their pages render properly. However, as browsers became more standards-compliant, these pages no longer rendered correctly, as they were written for what bascially was a different type of CSS. This is where quirks mode comes in, as it handles pages written for these broken CSS implementations.

在过去,当 Web 浏览器没有完整/正确的 CSS 实现时,开发人员依靠这些特性来使他们的页面正确呈现。然而,随着浏览器变得更加符合标准,这些页面不再正确呈现,因为它们是为基本上不同类型的 CSS 编写的。这就是 quirks 模式的用武之地,因为它处理为这些损坏的 CSS 实现编写的页面。

So in 2009, you don't really need to worry about quirks mode unless you're handling older CSS, or older browsers. Just write your CSS to current web standards, and you be OK.

因此,在 2009 年,除非您正在处理较旧的 CSS 或较旧的浏览器,否则您实际上不必担心 quirks 模式。只需按照当前的 Web 标准编写 CSS,就可以了。

回答by Khalid Azam

http://www.motive.co.nz/glossary/quirks-mode.php

http://www.motive.co.nz/glossary/quirks-mode.php

  • In quirks mode, the web browser attempts to render code based on a ‘best-guess', this includes a generous interpretation of code that may be non-standard or poorly-formed.
  • A web browser may switch to quirks mode if a webpage has no document type declaration or has an incomplete document type declaration (for example, if the URI to the DTD is omitted).
  • Quirks mode enables older HTML documents to still ‘work', and should be triggered when the code that has been used is known to fail contemporary technical standards (and when there is no intention/budget to revise legacy content).
  • 在 quirks 模式下,Web 浏览器尝试根据“最佳猜测”呈现代码,这包括对可能是非标准或格式不佳的代码的大量解释。
  • 如果网页没有文档类型声明或文档类型声明不完整(例如,如果省略了 DTD 的 URI),Web 浏览器可能会切换到 quirks 模式。
  • Quirks 模式使旧的 HTML 文档仍然可以“工作”,并且应该在已知已使用的代码不符合当代技术标准(并且没有意图/预算来修改遗留内容时)时触发。

回答by snr

Trust my answer tested by me almost always, not its votes especially received from needless guys.

相信我的答案几乎总是经过我的测试,而不是特别是从不必要的人那里得到的选票。



In addition to other answers, the mode can be checked by

除了其他答案外,还可以通过以下方式检查模式

javascript:window.alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode.')