删除/重置 CSS 行为属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4513738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:22:07  来源:igfitidea点击:

Remove/reset CSS behavior property

cssinternet-explorerbehaviorhtml-components

提问by Jeremy Kauffman

Is it possible to remove the IE-specific behavior CSS property via a more specific rule or the !importantdeclaration? Example:

是否可以通过更具体的规则或!important声明删除特定于 IE 的行为 CSS 属性?例子:

.a-rule
{
  behavior: url(/some.htc);
}
.a-rule.more-specific
{
  behavior: /*no HTC*/
}

I realize that overriding CSS properties is undesirable, but I'm stuck here.

我意识到覆盖 CSS 属性是不可取的,但我被困在这里。

On Edit: I'm not sure where people are getting confused about this question. For all purposes, you can consider this already being an IE specific stylesheet. I'm asking how, if .a-ruleabove exists and is immutable, how can one remove the behavior via a more specific rule? A standard CSS equivalent would be:

关于编辑:我不确定人们在哪里对这个问题感到困惑。出于所有目的,您可以认为这已经是 IE 特定的样式表。我在问如何,如果.a-rule上述存在并且是不可变的,如何通过更具体的规则删除行为?标准的 CSS 等效项是:

.a-rule
{
  border: 1px solid black;
}
.a-rule.more-specific
{
  border: 0 none;
}

One can reset the border property for a subset of elements via a more specific rule. I'm asking how to reset the behavior property in an analogous way.

可以通过更具体的规则重置元素子集的边框属性。我在问如何以类似的方式重置行为属性。

回答by Jeremy Kauffman

The default value is "none". See:

默认值为“无”。看:

What is the *correct* way to unset the behavior property in CSS?

在 CSS 中取消设置行为属性的*正确* 方法是什么?

The solution:

解决方案:

.a-rule
{
  behavior: url(/some.htc);
}
.a-rule.more-specific
{
  behavior: none;
}

回答by haha

.a_rule {
  border: 1px solid black; /* we know border is black */
  behavior: url(/some.htc) /* we know something happen inside some.htc */
}
 .a_rule.more-specific {
  border: 0 none; /* we remove the border */
  behavior: url(/some.htc) /* we remove something inside some.htc */
}

use different .htcfile

使用不同的.htc文件

回答by Cole

Maybe use conditional tags for IE in your head

也许在你的脑海中为 IE 使用条件标签

<!--[if IE]>
<style type="text/css">
    .a-rule {
       behavior: url(/some.htc);
    }
</style>
<![endif]-->