Why use DOCTYPE HTML_HTML/Xhtml_webpage production

WBOY
Release: 2016-05-16 16:41:39
Original
1596 people have browsed it

You know that without it, the browser will use weird mode when rendering the page; you know that each browser renders various elements differently in weird mode. So you would write a doctype like this:

Copy the code
The code is as follows:

< ;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Fortunately, various web development tools nowadays are powerful enough to support inserting template code, so you don’t need to type out this long and smelly doctype letter by letter. But if you’re fed up with it, you might try this:

Copy the code
The code is as follows:



Wow, so simple! The benefits are obvious: 1. You can easily write this doctype without worrying about making mistakes; 2. You save about 105 bytes of characters. For a site with a daily PV of tens of millions, it can save a lot of money. Objective traffic; 3. It is backward compatible. Yes, the doctype of html5 is written like this, and modern browsers recognize it.

If you are like me and have always thought: Not specifying dtd will open the weird mode of the browser , this statement is wrong! The correct statement is that weird mode will be turned on if doctype is not defined, which means that you only need to define to let the browser render the page in strict mode (standard mode) without specifying A certain type of dtd. Let's review that all browsers require two modes: weird mode and strict mode (also called standards mode). IE 6 for Windows/mac, Mozilla, Safari and Opera all implement these two modes, but versions below IE 6 are always in weird mode. Here are a few things you need to know about the two modes:

  1. Pages written before standardization did not have a doctype, so pages without a doctype were rendered in weird mode.
  2. On the other hand, if the doctype added by the web developer means that he knows what he has to do, most doctypes will turn on strict mode (standards mode), and the page will be rendered according to standards.
  3. Any new or unknown doctype will turn on strict mode (standards mode).
  4. Every browser has its own way of activating weird mode. You can take a look at this list: http://hsivonen.iki.fi/doctype/

Note: You don’t need to validate your page against the doctype you choose at all. As long as the doctype tag exists, it is enough to enable strict mode (standards mode). If you still have doubts about what I said, then please go to http://www.quirksmode.org/css/quirksmode.html#link2 to learn what you want to know. We only need a short piece of JavaScript code to get the answer, it is:

Copy the code
The code is as follows:

mode=document.compatMode;

This code can be used to determine whether the current browser is in weird mode or standard mode. There is no doubt about the compatibility of this attribute. If you have doubts, you can check http://www.quirksmode.org/dom /w3c_html.html#t11. You can visit: http://wanz.im/demo/doctype-test.html in the browser you want to test, and you can see the results. As far as I know, this is not activated. Weird mode, even under ie6, if you have any new discoveries, please leave me a message.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!