HTML条件注释用法诠释

注释内容以样式为例,如下:

1、支持所有IE浏览器


<!--[if IE]>

<link rel="stylesheet" href="all-ie-only.css" type="text/css"/>

<![endif]-->

2、支持非IE浏览器

<!--[if !IE]>

<link rel="stylesheet" href="not-ie.css" type="text/css"/>

<![endif]-->

上面是除了IE浏览器外所有浏览器都识别这个样式,另外CSS-TRICKS的《How To Create an IE-Only Stylesheet》一文中提供了另一种写法:

<!--[if !IE]><!-->
``` ``` 3、仅仅支持IE10
<!--[if IE 10]>

<link rel="stylesheet" type="text/css" href="ie10.css">

<![endif]-->

4、仅仅支持IE9

<!--[if IE 9]>

<link rel="stylesheet" type="text/css" href="ie9.css">

<![endif]-->

5、仅仅支持IE8

<!--[if IE 8]>

<link rel="stylesheet" type="text/css" href="ie8.css">

<![endif]-->

6、仅仅支持IE7

<!--[if IE 7]>

<link rel="stylesheet" type="text/css" href="ie7.css">

<![endif]-->

7、仅仅支持IE6

<!--[if IE 6]>

<link rel="stylesheet" type="text/css" href="ie6.css">

<![endif]-->

8、支持IE10以下版本(IE9以及IE9以下版本)

这种方法是样式表使用在低于IE10的浏览器,换句话说除了IE10以外的所有IE版本都将被支持。

<!--[if lt IE 10]>

<link rel="stylesheet" type="text/css" href="ie9-and-down.css">

<![endif]-->

也可以写成

<!--[if lte IE 9]>

<link rel="stylesheet" type="text/css" href="ie9-and-down.css">

<![endif]-->

前面我们也说过了lt和lte的区别,lt表示小于版本号,不包括条件版本号本身;而lte是小于或等于版本号,包括了版本号自身。

9、支持IE9以下版本(IE8以及IE8以下版本)

<!--[if lt IE 9]>

<link rel="stylesheet" type="text/css" href="ie8-and-down.css">

<![endif]-->

或:

<!--[if lte IE 8]>

<link rel="stylesheet" type="text/css" href="ie8-and-down.css">

<![endif]-->

10、支持IE8以下版本(IE7以及IE7以下版本)

<!--[if lt IE 8]>

<link rel="stylesheet" type="text/css" href="ie7-and-down.css">

<![endif]-->

或:

<!--[if lte IE 7]>

<link rel="stylesheet" type="text/css" href="ie7-and-down.css">

<![endif]-->

11、支持IE7以下版本(IE6以及IE6以下版本)

<!--[if lt IE 7]>

<link rel="stylesheet" type="text/css" href="ie6-and-down.css">

<![endif]-->

或:

<!--[if lte IE 6]>

<link rel="stylesheet" type="text/css" href="ie6-and-down.css">

<![endif]-->

上面8——11这几种方法,使用的是低于(lt)和低于或等于(lte)的方法来判断,我们也可以使用大于(gt)和大于或等于(gte)达到上面的效果:

12、高于IE9的版本(IE10以及IE10以上版本)

<!--[if gt IE 9]>

<link rel="stylesheet" type="text/css" href="ie10-and-up.css">

<![endif]-->

或:

<!--[if gte IE 10]>

<link rel="stylesheet" type="text/css" href="ie10-and-up.css">

<![endif]-->

13、高于IE8的版本(IE9以及IE9以上版本)

<!--[if gt IE 8]>

<link rel="stylesheet" type="text/css" href="ie9-and-up.css">

<![endif]-->

或:

<!--[if gte IE 9]>

<link rel="stylesheet" type="text/css" href="ie9-and-up.css">

<![endif]-->

14、高于IE7的版本(IE8以及IE8以上版本)

<!--[if gt IE 7]>

<link rel="stylesheet" type="text/css" href="ie8-and-up.css">

<![endif]-->

或:

<!--[if gte IE 8]>

<link rel="stylesheet" type="text/css" href="ie8-and-up.css">

<![endif]-->

15、高于IE6的版本(IE7以及IE7以上版本)

<!--[if gt IE 6]>

<link rel="stylesheet" type="text/css" href="ie7-and-up.css">

<![endif]-->

或:

<!--[if gte IE 7]>

<link rel="stylesheet" type="text/css" href="ie7-and-up.css">

<![endif]-->

16、高于IE5.5的版本(IE6以及IE6以上版本)

<!--[if gt IE 5.5]>

<link rel="stylesheet" type="text/css" href="ie6-and-up.css">

<![endif]-->

或:

<!--[if gte IE 6]>

<link rel="stylesheet" type="text/css" href="ie6-and-up.css">

<![endif]-->

注明:以上 内容来自浏览器兼容之旅的第一站:如何创建条件样式 ,转载请注明,谢谢…

对上文的一点补充:

17、指定多种IE版本

<!--[if (IE 6)|(IE 7)|(IE 8)]>

<link rel="stylesheet" type="text/css" href="ie6-7-8.css">

<![endif]-->
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值