CSS useragent (simple browser differentiation)

Source: Internet
Author: User

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>

 

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.