The principle of CSS:
We know that CSS is written in different places with different priorities,. css file definitions < elements in the style, but if you use!important, things will get a difference.
First, let's look at the following code:
<!DOCTYPEHtml><Html><Head><MetaHttp-equiv= "Content-type"Content= "text/html; Charset=utf-8 "><Title> Test in CSS! Important differences</Title></head> < style type= "text/css" >.testclass {Color:blue!important;} </style>< body> <div Class= "TestClass" style= "color:red;" > test css important </div>< Span class= "KWRD" ></body></ html>
Although the style of the element has the definition of the TestClass class, the!important-qualified definition in the above CSS definition is the highest priority, both in the ie6-10 or in Firefox and Chrome, both of which are displayed in blue.
This situation can also indicate that IE6 can identify!important, but this is a flaw in IE6. If written in the following style, IE6 is not recognized:
. testclass{Color:blue!important;color:red;}
In this way, it appears red when displayed under IE6.
Of course, IE6 can also be identified by the following methods:
. testclass{
Color:blue!important;
}
. testclass{
color:red;
}
It is also possible to make the IE6 appear blue by the above method.
The above example shows that CSS definitions using!important have the highest precedence. Just in the IE6 out a little bit of bug, note that the writing method is generally easy to avoid.
The use of!important in CSS