Quirks模式是什么?_html/css_WEB-ITnose
什么是DOCTYPE:
DOCTYPE,或者称为 Document Type Declaration(文档类型声明,缩写 DTD)。通常情况下,DOCTYPE 位于一个 HTML 文档的最前面的
位置,位于根元素 HTML 的起始标签之前。这样一来,在浏览器解析 HTML 文档正文之前就可以确定当前文档的类型,以决定其需要采用的
渲染模式(不同的渲染模式会影响到浏览器对于 CSS 代码甚至 JavaScript 脚本的解析)。
在写程序时我们也会经常遇到这样的问题,如何保证原来的接口不变,又提供更强大的功能,尤其是新功能不兼容旧功能时。遇到这种问题时的一个常见做法 是增加参数和分支,即当某个参数为真时,我们就使用新功能,而如果这个参数 不为真时,就使用旧功能,这样就能不破坏原有的程序,又提供新功能。IE6也 是类似这样做的,它将DTD当成了这个“参数”,因为以前的页面大家都不会去写DTD,所以IE6就假定 如果写了DTD,就意味着这个页面将采用对 CSS支持更好的布局,而如果没有,则采用兼容之前的布局方式。这就是Quirks模式(怪癖模式,诡异模式,怪异模式)。
DOCTYPE与各种模式的关系:
混杂模式:
不写DOCTYPE
近似标准模式:
标准模式:
我们可以看到,过渡型或框架型HTML声明与过渡型或框架型XHTML声明均可使浏览器进入近似标准模式,同时,html5的DOCTYPE声明和严
格型HTML声明以及严格型XHTML声明则会使浏览器进入标准模式。
三种模式下的表现差异:
首先,混杂模式是不可取的,因为其没有兼容性可言。在IE(IE6~IE9)中,混杂模式即使用IE5.5内核来解析并渲染页面。其次,近似标准
模式是在尽可能遵循标准的基础上兼容部分非标准代码,比如一些已经弃用的标签等。标准模式则是对统一标准实现最好的模式,它要求标
签必须闭合(唯一不需要闭合的就是DOCTYPE标签),不能使用已经废弃的标签等等。目前,使用最多的DOCTYPE声明为过渡型HTML或
XHTML,因为它能最大话的兼容一些老代码。不过,技术领先的公司(比如google、facebook、twitter等都如此)都已经使用了html5的
DOCTYPE声明,即,它所触发的模式与严格型HTML或严格型XHTML所触发的模式完全相同,但好处是节省代码且向前兼
容(HTML5时代)。
1.在Quirks 模式下,IE的宽度和高度还包含了padding和border。
2.设置行内元素的高宽:在Standards模式下,给等行内元素设置wdith和height都不会生效,而在quirks模式下,则会生效。margin:0 auto设置水平居中:使用margin:0 auto在standards模式下可以使元素水平居中,但在 quirks模式下却会失效。 IE6/7及IE8混杂模式(quirks模式)中,text- align:center可以使块级元素也居中对齐。其他浏览器中,text-align:center仅作用于行内内容上。
解决这个问题比较好的方式,就是为所有需要相对父容器居中对齐的块级元素设置“margin:0 auto”。但这个方式 IE6/IE7/IE8的混杂模式中不支持,所以还要设置父容器的 "text-align:center;"。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati
