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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to distinguish between closing tabs and closing entire browser using JavaScript on your browser? During the daily use of the browser, users may...
