CSS hack is usually used to ensure compatibility with multiple browsers.
# Test {
Color: red;/* all browsers support */
Color: red! Important;/* supported by Firefox and IE7 */
_ Color: red;/* IE6 supported */
* Color: red;/* IE6 and IE7 */
* + Color: red;/* IE7 supported */
Color: Red \ 9;/* IE6, IE7, and IE8 support */
Color: Red \ 0;/* IE8 supported */
}
When I read www.laiwang.com today, I found that the class attribute of his html contains the following information.
UA-WebKit ua-webkit-535 ua-webkit-535-2 UA-chrome ua-chrome-15 ua-chrome-15-0 ua-chrome-15-0-874 ua-chrome-15-0-874-121 JS
View its JS and find that it is implemented by cssua.
Official Website: http://cssuseragent.org/
The principle is to use js to add a class containing browser information to HTML.
In this way, you can differentiate browsers in CSS as follows:
. Ua-Chrome
{
Color: red;
}
. Ua-ie
{
Color: blue;
}
There is a similar implementation of http://rafael.adm.br/css_browser_selector/ abroad
Instance download: http://files.cnblogs.com/zjfree/cssua.rar
Another method to differentiate ie versions
Use
<! -- [If lt IE 7]> <HTML class = "ie IE6"> <! [Endif] -->
<! -- [If IE 7]> <HTML class = "ie IE7"> <! [Endif] -->
<! -- [If IE 8]> <HTML class = "ie IE8"> <! [Endif] -->
<! -- [If IE 9]> <HTML class = "ie ie9"> <! [Endif] -->
<! -- [If (GT ie 9) |! (IE)]> <! --> <HTML> <! -- <! [Endif] -->
Replace<HTML>