Two ways to load different CSS for different browsers

Source: Internet
Author: User

Because of the browser (IE, Gecko, opera ...) The rendering of the CSS is different, resulting in differences in display, so you can load a different way to solve the CSS, the following introduction to the next two methods to achieve, not necessarily very practical, difficult to play a.

Pure CSS Way

The following is a reference fragment:

Code

. box{

Width:20em;

Height:20em;

Background: #369;

}

/*--gecko Kernel--*/

@mediaalland (min-width:0px) {

box{

Background: #CC0000;

}

}

/*--operahacks--*/

/*--cannot pass W3CCSS test--*/

The above code runs the result, in IE is gray, opera is mauve, Firefox is blue

Previous versions of IE7 can also be distinguished by CSS2 attribute selectors, which unfortunately IE7 begin to recognize.

This article is published by Forestgan in 15-oct-2006

The method of JavaScript

The following is a reference fragment:

Varcss_browser_selector=function () {

Var

Ua=navigator.useragent.tolowercase (),

Is=function (t) {Returnua.indexof (t)!=-1;},

H=document.getelementsbytagname (' HTML ') [0],

b= (!) ( /opera|webtv/i.test (UA)) &&/msie (d)/.test (UA))? (Is (' Mac ')? Iemac ': ') + ' Ieie ' +regexp.$1)

: Is (' gecko/')? Gecko ': Is (' opera ')? Opera ': Is (' Konqueror ')? Konqueror ': Is (' applewebkit/')? Webkitsafari ': Is (' mozilla/')? Gecko ': ',

Os= (Is (' x11 ') | | Is (' Linux '))? ' Linux ': Is (' Mac ')? Mac ': Is (' win ')? Win ': ';

varc=b+os+ ' JS ';

H.classname+=h.classname? ' +C:C;

}();

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.