`

判断浏览器

    博客分类:
  • CSS
阅读更多

<html>
<head>
<title>css</title>
<style type="text/css">
/*\*//*/ #example{color:#00f ;} /**/
#example{color:red;}/*firefox*/
* html #example{color:blue;}/*ie6*/
*+html #example{color:green;}/*ie7*/
</style>
</head>
<body>
<div id="example">
sdfadfasfafd
</div>
</body>
</html>

 

 

//条件注释只有在IE浏览器下才能执行,默认的css要放在前面
<!– 默认先调用css.css样式表 –>
<link rel="stylesheet" type="text/css" href="css.css" />
<!–[if IE 7]>
<!– 如果IE浏览器版是7,调用ie7.css样式表 –>
<link rel="stylesheet" type="text/css" href="ie7.css" />
<![endif]–>
<!–[if lte IE 6]>
<!– 如果IE浏览器版本小于等于6,调用ie.css样式表 –>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]–>


<style type="text/css">
body{
background-color: #000;
}
</style>
<!–[if IE]>
<style type="text/css">
body{
background-color: #F00;
}
</style>
<![endif]–>


<SCRIPT LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//如果浏览器为IE
setActiveStyleSheet("default.css");
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//如果浏览器为Firefox
setActiveStyleSheet("default2.css");
}else{
//如果浏览器为其他
setActiveStyleSheet("newsky.css");
}
}

function setActiveStyleSheet(title){
  document.getElementsByTagName("link")[0].href="style/"+title;
}
//--></SCRIPT>
document.write('<link rel="stylesheet" type="text/css" id="css" href="style.css">')

//如果你只是为了兼容ie7和8,其实可以在<head>里加上这样一条代码:
<meta http-equiv="X-UA-Compatible" content="IE=7"> 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics