Home  >  Article  >  Web Front-end  >  Summary of CSS Hacking methods for specifying the doctype of a web page

Summary of CSS Hacking methods for specifying the doctype of a web page

高洛峰
高洛峰Original
2017-02-13 14:04:421453browse

We all know that to be a WD (web designer), you must first serve several browsers: IE6, IE7, and Firefox. General pages only need to work normally under IE6, IE7, and Firefox.

But in fact, there are far more than just these browsers. Firefox is divided into several major versions: Firefox 1.5, Firefox 2, and Firefox 3. There are also several series in IE7 and IE6. In addition to these two In addition to products from mainstream manufacturers, there are also a series of Opera, Konqueror, Netscape, chrome, etc.

Each of these browsers has its own set of rules. It often runs normally here and not properly there. So WD demolished the east and repaired the west, and finally it worked normally under several browsers. As a result, the product manager had new needs and needed to make changes here and there. As a result, the paper frame that had been finally fooled suddenly collapsed, and the WDs were extremely busy again. The reason why I say this is because this is my experience.

Usually WD always collects a bunch of Css Hacking skills in order to make it work properly under various browsers. Searching online, there are a lot of them.

However, first of all, WD did not figure out a basic question, why do we need css Hacking? If there are 1,000 browsers, do we need to remember the Hack skills of 1,000 browsers?

In fact, CSS Hacking is something that cannot be brought to the table to some extent. There are many techniques in Css Hacking, which simply take advantage of browser bugs. For example, it is common to use _class{….} ​​to distinguish between IE and Firefox. Logically speaking, _class is an illegal tagging method. The emergence of Css Hacking is a last resort for WDs. The daily work of WDs is not crazy Css Hacking.

In fact, there are so many browsers that you can’t just mess around and define whatever you want. Define a mark. People are accustomed to living in a standard world, and in the web world, there are also a series of standards. Browsers are also working hard to be compatible with web standards. But some browsers debuted early, and it can be said that the web standards that emerged later were born under their influence. There is another person who was very good at that time, so he made a lot of innovations and didn't take web standards to heart. He didn't care. What's more, the standards themselves are constantly being updated. Therefore, generally every browser product system went through a period of time when they didn't care much about web standards. Later, everyone realized that it was no longer possible. We all compromised and established a set of standards that everyone would abide by. But in the past, each company had some small rules and regulations that they had formulated. What should they do if they did not meet the standards?

So, these people came up with a way: standard mode and weird mode. There is another one called "almost standard mode", almost standard. It's so weird that I almost fainted. Don't worry, listen to me slowly.

Didn’t I say that these bosses sat together and formulated various standards. In the future, everyone will interpret web pages according to this set of standards. If the web page you make can be interpreted according to this set of standards, then use a tag doctype to indicate that it can be interpreted according to web standards. This is the standard mode.

Then what should I do if the Xiaojiujiu products that have been produced by various companies in the past do not meet the standards? You can't just throw them all away right away, right? There is probably a set of principles in software called backward compatibility. In weird mode, each browser simulates the operation of those older versions of the browser to prevent older pages from not working. When the web page does not specify a doctype, the browser usually works in a weird mode to prevent the old page from working.

The most notable example of the difference between these two modes involves IE's proprietary box model on Windows. When IE 6 came out, the correct box model was used in standards mode and the old proprietary box model was used in weirdness mode. To maintain backward compatibility with IE 5 and earlier, Opera 7 and later also use the flawed IE box model in weird mode.

Mozilla and Safari also have a third mode called "almost standards mode", which is the same as standards, except for some minor differences in how tables are handled. The pattern is the same.

It is for this reason that you can throw away a lot of css hacking techniques. Some books say that the box model (or box model in some places) of IE6 and Firefox are inconsistent, so you need to do this hack:

p{
width:100px;
*width:95px ;
}

I say, this kind of book is really misleading. Because, as long as the doctype is specified correctly, these differences in browser interpretation will disappear, and we can just follow the standard.

This mode is specified by the DOCTYPE field located at the beginning of the HTML file. The common ones are as follows:

HTML 4.01 Transitional:

Copy code The code is as follows:





HTML 4.01 Frameset

Copy code The code is as follows:





XHTML 1.0 Strict

##Copy code The code is as follows:

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


XHTML 1.0 Transitional


Copy code The code is as follows:




 XHTML 1.0 Frameset


Copy code The code is as follows:



 XHTML 1.1


##Copy code

The code is as follows:



For more summary of CSS Hacking methods to solve the doctype of specified web pages, please pay attention to PHP for related articles Chinese website!

Statement:
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