我需要为 IE 和所有其他浏览器包含不同的 .css 文件。
我尝试了以下但它不起作用。
<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style.css">
<!--<![end if]-->
<!--[if IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css">
<!--<![end if]-->
我需要为 IE 和所有其他浏览器包含不同的 .css 文件。
我尝试了以下但它不起作用。
<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style.css">
<!--<![end if]-->
<!--[if IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css">
<!--<![end if]-->
这是一个很好的页面,它提供了您正在寻找的示例的一个很好的列表:
针对所有版本的 IE
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
定位除 IE 之外的所有内容
<!--[if !IE]><!-->
<link rel="stylesheet" type="text/css" href="not-ie.css" />
<!--<![endif]-->
仅针对 IE 7
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->
仅针对 IE 6
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
目标 IE 6 和更低版本
<!--[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]-->
目标 IE 7 及更低版本
<!--[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]-->
目标 IE 8 和更低版本
<!--[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]-->
目标 IE 7 和更高版本
<!--[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]-->
目标 IE 8 和更高版本
<!--[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]-->
您可以通过这种方式为 IE 条件提供 css 路径。
<!--[if IE]>
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css">
<![endif]-->
<!--[if !IE]> -->
<link type="text/css" rel="stylesheet" href="css/my_style.css">
<!-- <![endif]-->
您可以从以下链接获得更好的帮助。
http://www.quirksmode.org/css/condcom.html
喜欢……!!:)
我认为您在链接元素的末尾错过了 />
<link type="text/css" rel="stylesheet" href="css/my_style.css" />
像这样尝试会发生什么?
<!--[if !IE]> -->
<link type="text/css" rel="stylesheet" href="css/my_style.css">
<!-- <![endif]-->
<!--[if IE]> -->
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css">
<!-- <![endif]-->
您在定义条件注释时遇到了几个错误:
<!--[if !IE]>
<link type="text/css" rel="stylesheet" href="css/my_style.css" />
<![endif]-->
<!--[if IE]>
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css" />
<![endif]-->
这应该可以解决问题。