首页 新闻 会员 周边

html如何区分浏览器

0
悬赏园豆:20 [已解决问题] 解决于 2014-09-29 15:27

<link href="../firefox.css" rel="stylesheet" type="text/css" />
<!--[if !IE]><!-->
<link href="../chrome.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if gte IE 7]><!-->
<link href="../ie11.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->

 

我想知道这个if里面到底区分的是什么,我这边有ie11浏览器,是不是if里面就应该写

<!--[if ie11]>。如果不知这个if后面的东西应该根据写。

还有就是怎么用这个区分ie11,谷歌,火狐浏览器,求实用代码谢啦

晓爽的主页 晓爽 | 初学一级 | 园豆:130
提问于:2014-09-29 11:36
< >
分享
最佳答案
0

这个是IE的条件注释。

gt lt lte  其实是大于(Greater Than ) 小于(Less Than) 大于等于(Less Than Equal) 的意思。

如果要区分FF和Chrome的,建议在这里用js来动态生成link元素。

if(ie){

  document.write('xxx');

}

这种。

收获园豆:20
幻天芒 | 高人七级 |园豆:37175 | 2014-09-29 12:16
其他回答(2)
0

<!--[if !IE]><!-->
<link href="../chrome.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->

假如不是IE浏览器,就链接chrome.css样式表。

<!--[if gte IE 7]><!-->
<link href="../ie11.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->

假如超过IE版本7(包括IE11),就按接ie11.css样式表。

 

条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>

爱编程的大叔 | 园豆:30839 (高人七级) | 2014-09-29 11:40

没用,我试过个,<!--[if !IE]><!-->
<link href="../chrome.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if gte IE 7]><!-->
<link href="../ie11.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->这两句无不管在谷歌还是ie都是执行最后那一句,那个链接我再问之前就看过了

支持(0) 反对(0) 晓爽 | 园豆:130 (初学一级) | 2014-09-29 11:54

@晓爽: IE11不支持这种html注释方法判断的。但是基于这种注释稍微变通个写法也可以实现的。

支持(0) 反对(0) i柚 | 园豆:202 (菜鸟二级) | 2017-03-20 17:37
0

这种条件注释只有IE才能认识的.

其它的浏览器还是用JS来区分比较好.

Albert Fei | 园豆:2102 (老鸟四级) | 2014-09-29 13:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册