DOCTYPE ignored in WEB Development

Source: Internet
Author: User

During web development, you often focus on interface design and data logic processing, but do not pay special attention to some details.

Doctype is one of them:

<! Doctype html public "-// W3C // dtd xhtml 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

1.doc type

The doctype label is used to specify the document dtd (Document Type Definition), which is written at the beginning of each html, such:

<! DOCTYPE RootElement Availability "URI" [declarations]>

For example, common doctype:

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">

XHTML 1.1 Strict DTD <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.1 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

2.doc type

If doctype is specified or different doctype is specified, different browser modes are activated, which may affect html, css, and js. The most famous one is the so-called box model.

2.1 why there are multiple modes

A long time ago, netscape and ie were competing for the world. Because it was so powerful, the browser mode was decided by the browser itself. As time passes, we suddenly see the age of heroes in the Warring States period. If everyone finds that if they have the say, the world will be in disorder. Then we will discuss how to recommend a leader, so w3c will be on stage. However, the problem arises again. For example, although IE cannot be the only one, it is the general trend to align with the standard. However, if the browser only supports the standard, many previous pages will have some problems.

So doctype came into being. If no doctype was specified, it would adopt the original Mode, known as Quirks Mode. If doctype was specified, it would follow the standard, it is called standard Mode or strict Mode ). During this period, the Mozilla representatives thought that the standard mode, such as the img Resolution, is not very suitable, so they kept some personal opinions. When some specific doctype is specified, A quasi-standard Mode (Almost Standards Mode) is used. For more information, see Activating Browser Modes with Doctype, or use doctype to activate the Browser Mode in @ net dance.

2.2 specific effects of different modes

@ Ppk Daniel has made a good conclusion for us, Quirks mode and strict mode.

3. Recommended doctype

<! Doctype html>

Reason: html5 is supported. Strict mode is adopted if you do not know anything.

Add some reset css, such as img {display: block} to solve the browser compatibility problem.

It should be noted that many people use it now <! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> and <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> in several major browsers, only the geek mode is used. In other words, you can skip this mode.

Related Article

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.