用CSS/Javascript來判斷瀏覽器類型

來源:互聯網
上載者:User

方法一:

<!--[if lte IE 6]> <LINK rel="stylesheet" type="text/css" href="images/style_IE5.css" /> <![endif]–> <!--[if IE 6]> <LINK rel="stylesheet" type="text/css" href="images/style_IE6.css" /> <![endif]--> <!--[if IE 7]> <LINK rel="stylesheet" type="text/css" href="images/style_IE7.css" /> <![endif]-->

適用瀏覽器:IE5以上的IE瀏覽器

使用技術:條件注釋

使用地點:HTML代碼中(注不是CSS裡)

比較符:

lte:就是Less than or equal to的簡寫,也就是小於或等於的意思。
lt :就是Less than的簡寫,也就是小於的意思。
gte:就是Greater than or equal to的簡寫,也就是大於或等於的意思。
gt :就是Greater than的簡寫,也就是大於的意思。
! :就是不等於的意思,跟javascript裡的不等於判斷符相同

 

方法二:

#example{color:red ;}/*firefox*/ * html #example{color:blue;}/*ie6*/ *+html #example{color:green;}/*ie7*/

使用地點:CSS中

 

方法三:

<link type="text/css" rel="stylesheet" href="css/screen.css" /> <link type="text/css" rel="stylesheet" href="css/screen.css" /> <script language="JavaScript" type="text/JavaScript"> <!-- //根據瀏覽器來選擇CSS if (!window.XMLHttpRequest) { setActiveStyleSheet("IE6.css"); //IE6 }else if(window.ActiveXObject){ setActiveStyleSheet("IE7.css"); //IE7 } else { setActiveStyleSheet("FireFox.css"); //Mozilla FireFox、Safari, etc. } function setActiveStyleSheet(filename){ var path = document.getElementsByTagName("link")[1].href; document.getElementsByTagName("link")[1].href="css/"+filename; } // --> <script>

這是利用不同版本瀏覽器建立XMLHttpRequest方式不同來選擇不同的CSS

相關文章

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.