如何覆盖过滤器:在CSS中没有



我有一个IE7特定的样式表,它适用于filter:none;我没有访问这个文件,所以不能简单地删除行。我需要通过CSS以某种方式覆盖它,以忽略正在设置的filter:none;

我已经尝试使用filter:; filter: -;filter: !important;,这应该导致过滤器属性无效,但过滤器仍在设置中。

是否有可能做到这一点,而不删除在IE7特定的样式表或使用javascript/jquery行?


答:

来解决我的具体问题,这是不可能简单地覆盖 filternull等效,因为我是问。正如下面的答案所建议的那样,必须通过将过滤器直接应用到我想要覆盖的地方来覆盖它。

IE7专用样式表:

.div.example { 
    filter:none;
}

覆盖:通用样式表:

.div.example {
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7F000000,endColorstr=#7F000000);
}

提取这个答案

微软引入-ms-filter使Internet Explorer更加标准兼容(CSS 2.1要求供应商扩展具有vendor前缀)。因为原来的filter属性的语法不是CSS 2.1IE8+要求-ms-filter属性的值为

-ms-filter: "progid:DXImageTransform.Microsoft.gradient(enabled=false)" /* IE 8+ */;
filter: none !important; /* IE 7 and the rest of the world */  

正如您所说,您需要覆盖现有的样式,因此添加!important

-ms-filter: "progid:DXImageTransform.Microsoft.gradient(enabled=false) !important";

如果你想知道,引号需要这个微软(-ms)供应商前缀。正如您所看到的,这个用例使用了MS的渐变,插入您希望覆盖的任何过滤器属性。

IE6IE7中,过滤器只应用于设置了属性的元素hasLayout。要删除hasLayout,可以通过添加以下属性和值之一的元素:

    position: static;
    float: none;
    width: auto; 
    height: auto; 
    overflow: visible;
    writing-mode: lr-tb | rl-tb | bt-rl;
    zoom: normal.

最新更新