IE7 CSS 继承不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/511066/
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 20:17:05  来源:igfitidea点击:

IE7 CSS inheritance does not work

cssinternet-explorerinternet-explorer-7

提问by Pawka

I have set some style for h2 tags (color, font-size, etc.), but when I put "A" tag inside, then style becomes as link. My html:

我已经为 h2 标签设置了一些样式(颜色、字体大小等),但是当我将“A”标签放入其中时,样式就变成了链接。我的html:

<h2>
  <a class="no-decor" href="http://localhost/xxx/">Link</a>
</h2>

So, as You can see, I've created "no-decor" class. It should inherit h2's style for "a" tag.

所以,如您所见,我创建了“无装饰”类。它应该继承 h2 的 "a" 标签样式。

a.no-decor {
  color:inherit;
  font-family:inherit;
  font-size:inherit;
  font-weight:inherit;
  text-decoration:inherit;
}

On Firefox everythig is ok, but IE still shows tag "a" style (underline text-decoration and blue color). I know, I can set some style for "h2 a", but maybe somehow it is possible to force work CSS inherit values on IE7?

在 Firefox 上一切正常,但 IE 仍然显示标签“a”样式(下划线文本装饰和蓝色)。我知道,我可以为“h2 a”设置一些样式,但也许可以以某种方式强制工作 CSS 在 IE7 上继承值?

P.S. On IE6 doesn't supports too.

PS On IE6 也不支持。

P.P.S. There is some example in same way: http://www.brunildo.org/test/inherit.html

PPS 有一些同样的例子:http: //www.brunildo.org/test/inherit.html

回答by bobince

No, IE has never supported inheritfor any property - sorry. This has been fixed in >= IE8.

不,IE 从未支持inherit任何属性 - 抱歉。这已在 >= IE8 中得到修复。

Whilst you could use a JavaScript fix to copy the properties from h2to a, it's probably easiest just to apply the same styling rule to both elements:

虽然你可以使用JavaScript修复的特性,从复制h2a,这是最简单的可能只是相同的式样规则适用于两个因素:

h2, h2 a {
    font: something;
    color: black;
    text-decoration: none;
}

You don't need to set inheriton text-decoration anyway, because decoration doesn't inherit from a parent into a child: the underline effect is on the parent and goes throughthe child; the child cannot remove it (modulo IE bugs). 'text-decoration: none' on the child is the right thing, unless you want potentially twounderlines...

inherit无论如何,您不需要设置text-decoration,因为装饰不会从父级继承到子级:下划线效果在父级上并通过子级;孩子无法删除它(模 IE 错误)。'text-decoration: none' 对孩子来说是正确的,除非你想要两个下划线......

回答by Carsen

try

尝试

a.no-decor{
  color:inherit;
  //color:expression(this.parentNode.currentStyle['color']);
  text-decoration:none;
}

That'll get rid of your blue color and the underline. You could use a similar expression for the underline, but you'd be better off just using text-decoration:none since that's all an inherited text-decoration is gonna give you anyhow and no need to use expressions when not absolutely necessary (you'll take a performance hit when using expressions).

这将摆脱你的蓝色和下划线。您可以对下划线使用类似的表达式,但最好只使用 text-decoration:none 因为这是所有继承的 text-decoration 无论如何都会给您的,并且在不是绝对必要时不需要使用表达式(您'使用表达式时会降低性能)。

回答by yoavf

A bug's a bug and there's nothing much you can do, short of workarounds.

错误就是错误,除了解决方法之外,您无能为力。

There's a test for inherit support here.

有对继承的支持测试在这里

You can also try to use a script like ie7-js, which "is a JavaScript library to make Microsoft Internet Explorer behave like a standards-compliant browser"

你也可以尝试使用像ie7-js这样的脚本,它“是一个 JavaScript 库,可以让 Microsoft Internet Explorer 表现得像一个符合标准的浏览器”

回答by Kld

Internet Explorer <= 7 versions don't support the value inheritfor any properties other than directionand visibility.

Internet Explorer <= 7 版本不支持和inherit以外的任何属性的值。directionvisibility