判断浏览器

<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"> 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值