Whether you are new to the front-end or you are already proficient in web Front-end development, you should know that when you write html, You need to define the document type. If you do not have it, browsers use the weird mode when rendering pages. You know that different browsers render different elements in the weird mode. So you will write a doctype like this:
The Code is as follows:
Fortunately, the various web development tools are powerful enough to support inserting template code, so you do not need to knock out the long and smelly doctype one by one. But if you have enough of it, you may try the following code:
The Code is as follows:
Wow, it's very concise! Obvious advantages: 1. You can easily write this doctype without worrying about writing errors. 2. You save about 105 bytes. For a site with a daily PV of tens of millions, it can save quite objective traffic. 3. It is backward compatible. Yes, the doctype of html5 is written in this way, and modern browsers know it.
If you always think:If no dtd is specified, the strange mode of the browser will be enabled.This is wrong!The correct statement should be that doctype is not defined to enable the weird mode, that is, you only need to defineThe browser can render the page in strict mode (standard mode) without specifying a type of dtd. Let's review that all browsers require two modes: the weird mode and the strict mode (also known as the standard mode ). Internet Explorer 6 for Windows/mac, Mozilla, Safari, and Opera both implement these two modes, but earlier versions of Internet Explorer 6 are always in the weird mode. You need to know the following about the two modes:
- Pages written before standardization do not have doctype, so pages without doctype are rendered in weird mode.
- Conversely, if a web Developer joins doctype, it means that he knows what he is going to do. Most doctype will enable strict mode (standard mode) and the page will be rendered according to the standard.
- Strict mode (standard mode) is enabled for any new or unknown doctype ).
- Each browser has its own method to activate the weird mode. You can look at this list: http://hsivonen.iki.fi/doctype/
Note: you do not need to verify your page based on your selected doctype. As long as the doctype tag exists, strict mode (standard mode) is enabled. If you are still skeptical about what I said, go to http://www.quirksmode.org/css/quirksmode.html?link2to understand the content you want to know. We only need a short JavaScript code to get the answer, which is:
The Code is as follows:
Mode = document. compatMode;
This code can be used to determine whether the browser is in the weird or standard mode. The compatibility of this attribute is beyond doubt. If you are skeptical, you can check http://www.quirksmode.org/dom/w3c_html.html#t11. You can access: Ghost in the browser you want to test.