我创建了一些IE条件评论,其中:
IE 8及以下版本将使用 .ie8AndBelow
IE 9将使用 .ie9
IE 10及以上不会添加任何类
*下面是我的代码:
<!DOCTYPE HTML>
<!--[if lte IE 8 ]><html class="ie8AndBelow"><![endif]-->
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<!--[if (gte IE 10)|!(IE)]><!-->
<html>
<!--<![endif]-->
<head>
</head>
....
....
然而,有一个问题,我如何编写仅针对IE浏览器的条件(无论任何版本),我想仅向Internet Explorer添加一个css调用 .ieOnly 。我得到的唯一解决方案是将它链接到另一个css文件,但不创建一个单独的类到html标签本身
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
答案 0 :(得分:0)
我不建议这样做,因为它在较新版本的IE中已被弃用,但如果您想使用它,则仅在IE5中添加支持,以便您可以使用:
<!--[if gte IE 5 ]><html class="ieOnly"><![endif]-->
这适用于IE5 +(当然没有人仍在使用旧版本),虽然支持已被删除,因此JavaScript解决方案可能会更好。这是一个可能的解决方案: Internet Explorer (IE) version detection in JavaScript