在IE上禁用css规则

时间:2013-10-15 14:02:30

标签: css background-image

我想知道你是否知道如何在客户端拥有即可启用或禁用css规则。

我有这种风格

 #number_one{
    background-image: url("../img/pins/1.png");    
    top: 250px;
    left: 115px;    
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/pins/1.png',sizingMethod='scale');
    -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/pins/1.png',sizingMethod='scale')";

}

我希望background-image能够在IE以外的所有浏览器上运行,因为过滤器会执行背景图片工作。

任何人都知道如何解决这个问题?非常感谢。

3 个答案:

答案 0 :(得分:6)

将IE包含在IE特定样式中并在此处覆盖CSS:

<!--[if IE]>
  <link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->

分别定位每个版本的IE也是可行的:

<!--[if IE 6]>
  <link rel="stylesheet" href="http://mysite.com/path/to/ie6-only.css" type="text/css" media="screen, projection">
<![endif]--> 

答案 1 :(得分:1)

一种简单的方法(不需要多个单独的样式表[顺便说一下也是如此])是用这个替换你的<html>标签:

<!--[if IE]>
 <html class="ie">
<![endif]-->

<!--[if !IE]>
 <html class="normal">
<![endif]-->

在你的CSS中,使用它来仅定位IE:

html.ie #number_one{
  background-image:none;
}

或者使用它来定位除IE以外的所有浏览器:

 html.normal #number_one{
    background-image: url("../img/pins/1.png");    
    top: 250px;
    left: 115px;    
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/pins/1.png',sizingMethod='scale');
    -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/pins/1.png',sizingMethod='scale')";

}

答案 2 :(得分:1)

您应该能够创建仅限IE的样式表,并使用我找到的方法相应地更改类:

要使用条件注释来定位IE,只需将此行添加到&gt; head&lt; HTML文件的标签:

1   <!--[if IE 6]><link rel="stylesheet" href="http://mysite.com/path/to/ie6.css"      type="text/css" media="screen, projection"><![endif]-->
2    
3   <!--[if IE 7]><link rel="stylesheet" href="http://mysite.com/path/to/ie7.css" type="text/css" media="screen, projection"><![endif]-->

这些条件注释将被其他所有浏览器忽略,因此只有IE 6和IE 7将分别加载这些样式表。现在你需要做的就是在你的服务器上创建文件并覆盖任何搞乱IE标题的CSS规则。

相关问题