CSS skills: the combination of important and space and other skills

Source: Internet
Author: User

! Important and (space)/**/: combination techniques and other
First, let's take a look at the cracking of IE's box-model.
The notorious bug of IE box-model exists in every previous version of IE6/Win. This bug was not released until tantak released the most widely spread hack.
IE5.X/win parses box-model in the same way. They think width includes border and padding. Fortunately, this has improved in IE6.
However, IE6 is backward compatible with previous errors. In fact, IE6 has two cores, and he still shows tolerance for errors before the old pages, IE6 can accept the correct box-model only when the DOCTYPE statement is strictly added to the document.
Therefore, the hack of tantak must be included in the document with the correct DOCTYPE to work properly.

The code is as follows: Copy code
Div. content {
Width: 400px; // This is the incorrect width, which is read by all browsers.
Voice-family: ""} "; // IE5.X/win ignores the content after" "}"
Voice-family: inherit;
Width: 300px; // Some browsers including IE6/win read this sentence. The new value (300px) overwrites the old one.
}
Html> body. content {// html> body is written in CSS2.
Width: 300px; // the browser that supports CSS2 is lucky enough to read this sentence.
}

Now back to the topic, we often see it! Important and (space)/**/: used together. What are the mysteries of this writing?
Let's look at the writing method. Here I can provide another writing method to achieve this effect.

The code is as follows: Copy code
Div. content {
Width: 300px! Important; // This is the correct width, most of which are supported! The browser marked with important uses the value here
Width (space)/**/: 400px; // IE6/win does not parse this sentence, so IE6/win still thinks that the width value is 300px; when IE5.X/win reads this sentence, the new value (400px) overwrites the old one because! Important flag does not work for them
}
Html> body. content {// html> body is written in CSS2.
Width: 300px; // the browser that supports CSS2 is lucky enough to read this sentence.
}

Similarly, this method can work normally only after the correct document type declaration, as mentioned earlier.
The document type declaration is like a switch that enables the future of backward compatibility. If it is used incorrectly, it is a Pandora box.

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.