DOCTYPE role? How is strict mode differentiated from promiscuous mode? What are their differences?

Source: Internet
Author: User

first, what is the role of DOCTYPE?

<! The doctype> declaration is called a file type definition (DTD), the function of the declaration in order to tell the browser the type of the file. Let the browser parser know which specification should be used to parse the document. <! The doctype> declaration must be in the first line of the HTML document, which is not an HTML tag.

second, how to distinguish between strict mode and promiscuous mode? What does it mean?

Strict mode:Also known as the standard mode, refers to the browser in accordance with the standards of code parsing.

Promiscuous mode:Also known as the quirks mode or compatibility mode, refers to the browser in its own way to parse the code.

how to differentiate:Whether strict or promiscuous mode is used in the browser parsing is directly related to the DTD in the Web page.

1, if the document contains strict DOCTYPE, then it is generally presented in strict mode.(Strict dtd--strict mode)
2. DOCTYPE, which contains the transition DTD and URI, is also rendered in strict mode, but there is a transition DTD and no URI (Uniform Resource Identifier, which is the last address of the declaration) causes the page to be rendered in promiscuous mode.(transition dtd--strict mode with URI; transition dtd--promiscuous mode without URI)
3. DOCTYPE is not present or incorrect form causes the document to be rendered in promiscuous mode.(DTD is not present or malformed--promiscuous mode)
4, HTML5 no DTD, so there is no strict mode and the difference between promiscuous mode, HTML5 has a relatively loose syntax, when implemented, has been as large as possible to achieve backward compatibility.(HTML5 no strict and mixed points)

Meaning:Strict mode and the existence of promiscuous mode is closely related to its origin, if there is only strict mode, then many old sites will inevitably be affected, if there is only promiscuous mode, then back then browser War chaos, each browser has its own parsing mode.

three, strict mode and promiscuous mode of statement resolution what are the different points?

1) The high width of the box model contains the inner margin padding and border border

In the Web Standard, if you set the width and height of an element, it refers to the width and height of the content of the element, and in IE5.5 and the following browsers and other versions of quirks mode, the width and height of IE also includes padding and border.

2) You can set the height of the elements in the line

In standards mode, setting Wdith and height for inline elements such as span will not take effect, and in quirks mode, it will take effect.

3) The height of the percentage can be set

In standards mode, the height of an element is determined by the content it contains, and if the parent element does not have a height set, the height of the child element setting a percentage is not valid.

4) Set the horizontal center with margin:0 Auto will be invalid under IE

Using margin:0 Auto in standards mode allows elements to be centered horizontally, but in quirks mode it will fail, quirk mode solution, with text-align properties:

Body{text-align:center}; #content {text-align:left}

5) Padding of the image set in quirk mode will fail

6) Font properties in table in Quirk mode cannot inherit settings from the upper layer

7) White-space:pre will fail in quirk mode


Supplemental content:

first, the use of specific statements:

1, HTML5 (one): <! DOCTYPE html>

2, HTML 4.01 (three kinds):Strict mode contains all HTML elements and attributes, but does not include the display and deprecated elements (such as font), the frameset (framesets), the transition pattern contains all the HTML elements and attributes, including the display and deprecated elements (such as font), Frameset (framesets) is not allowed, frame mode is equivalent to transition mode, but frameset content is allowed.

HTML 4.01 Strict: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >

HTML 4.01 Transitional: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >

HTML 4.01 Frameset: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 frameset//en" "HTTP://WWW.W3.ORG/TR/HTML4/FRAMESET.DTD" >

3. XHTML 1.0 (four types):The first three modes, XHML, must be marked with well-formed XML.

XHTML 1.0 Strict: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >

XHTML 1.0 Transitional: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

XHTML 1.0 Frameset: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 frameset//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" >

XHTML 1.1 This DTD equates to XHTML 1.0 Strict, but allows the addition of models. <! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

Ii. The source of strict mode and promiscuous mode


When Netscape4 (Netscape's early browser) and IE4 (Microsoft's early browser) implemented the CSS mechanism, they did not follow the standards presented by the Web. Netscape4 provided poor support, while IE4, though close to the standard, still failed to fully correct the standard of support. Although IE 5 fixes many of the problems with IE4, it still continues with other failures in the CSS implementation (mainly the box model problem).

In order to ensure that their website is displayed correctly on each browser, Web developers have to use CSS according to the specifications of each browser, so the CSS implementations of most Web sites do not conform to the standard.

However, as standard consistency becomes more important, browser developers have to face a difficult choice: Gradually following the standard is the way forward. But changing the existing CSS, completely to follow the standard, will make many old sites more or less destroyed, if the browser suddenly in the correct way to parse the existing CSS, the old site display will inevitably be affected. Therefore, all browsers need to provide two modes: Promiscuous mode serves legacy rules, while strict mode serves standard rules.

DOCTYPE role? How is strict mode differentiated from promiscuous mode? What are their differences?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.