好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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]><!--><link rel="stylesheet" type="text/css" href="not-ie.css" /><!--<![endif]--> 

3、仅仅支持IE10
<!--[if IE 10]>
<link rel="stylesheet" type="text/css" href="ie10.css">
<![endif]--> 

4、支持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是小于或等于版本号,包括了版本号自身 。

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

5、高于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]--> 

6、指定多种IE版本
<!--[if (IE 6)|(IE 7)|(IE 8)]>
<link rel="stylesheet" type="text/css" href="ie6-7-8.css">
<![endif]--> 

参考:
https://www.cnblogs.com/hushufang/p/3708704.html

相关推荐:

HTML5中audio与video标签的使用

以上就是HTML条件注释用法诠释的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于HTML条件注释用法诠释的详细内容...

  阅读:33次