条件注释区分非IE浏览器

IE浏览器的条件注释虽不太常用,却异常强大,不仅可以用来区分IE浏览器版本

<!--[if IE]> Only IE <![endif]-->
所有的IE可识别
<!--[if IE 5.0]> Only IE 5.0 <![endif]-->
只有IE5.0可以识别
<!--[if gt IE 5.0]> Only IE 5.0+ <![endif]-->
高于IE5.0都可以识别
<!--[if lt IE 6]> Only IE 6- <![endif]-->
低于IE6可识别
<!--[if gte IE 6]> Only IE 6/+ <![endif]-->
IE6以及IE6以上都可识别
<!--[if lte IE 7]> Only IE 7/- <![endif]-->
IE7及ie7以下版本可识别

lte:就是Less than or equal to的简写,也就是小于或等于的意思。

lt :就是Less than的简写,也就是小于的意思。

gte:就是Greater than or equal to的简写,也就是大于或等于的意思。

gt :就是Greater than的简写,也就是大于的意思。

! :就是不等于的意思,跟javascript里的不等于判断符相同


看到这里只可能会觉得<!--[if !IE]> not IE<![endif]-->这样不就可以了吗?

如果你这样想就错了,因为非ie根本不会识别ie的条件注释,所以就直接全部是注释了,
ok,来看看正确的写法吧

<!-- [if !IE]>< -->
只有不是ie浏览器才能看到这里
<! [endif]-- >
本来准备到这里加点内容只有非ie能看到的,被编辑器编码了,^_^,现在试试吧,只有非ie能看到哦,
关键是条件注释后头的 <–> 在IE中被当作内部注释,而在非IE浏览器中会闭合之前的注释,从而起到区分非IE浏览器的作用,一般常用<!–>。

More:

<!--[if lt IE 7 ]> <html class="ie ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->


If you could provide any suggestions or comments for this article, it is always welcome.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值