问题描述
我已经为 h2 标签设置了一些样式(颜色、字体大小等),但是当我将A"标签放入其中时,样式就变成了链接.我的 html:
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 class="no-decor" href="http://localhost/xxx/">Link</a>
</h2>
所以,如您所见,我创建了无装饰"类.它应该继承 h2 的 "a" 标签样式.
So, as You can see, I've created "no-decor" class. It should inherit h2's style for "a" tag.
a.no-decor {
color:inherit;
font-family:inherit;
font-size:inherit;
font-weight:inherit;
text-decoration:inherit;
}
在 Firefox 上一切正常,但 IE 仍然显示标签a"样式(下划线文本装饰和蓝色).我知道,我可以为h2 a"设置一些样式,但也许可以通过某种方式在 IE7 上强制工作 CSS 继承值?
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?
附言在 IE6 上也不支持.
P.S. On IE6 doesn't supports too.
P.P.S.有一些同样的例子:http://www.brunildo.org/test/inherit.html
P.P.S. There is some example in same way: http://www.brunildo.org/test/inherit.html
推荐答案
不,IE 从未支持任何属性的 inherit
- 抱歉.这已在 >= IE8 中得到修复.
No, IE has never supported inherit
for any property - sorry. This has been fixed in >= IE8.
虽然您可以使用 JavaScript 修复程序将属性从 h2
复制到 a
,但将相同的样式规则应用于两个元素可能是最简单的:
Whilst you could use a JavaScript fix to copy the properties from h2
to a
, it's probably easiest just to apply the same styling rule to both elements:
h2, h2 a {
font: something;
color: black;
text-decoration: none;
}
无论如何你都不需要在 text-decoration 上设置 inherit
,因为装饰不会从父级继承到子级:下划线效果在父级上并且通过 孩子;孩子无法删除它(模 IE 错误).'text-decoration: none' 对孩子来说是正确的,除非你想要潜在的两个下划线......
You don't need to set inherit
on text-decoration anyway, because decoration doesn't inherit from a parent into a child: the underline effect is on the parent and goes through the child; the child cannot remove it (modulo IE bugs). 'text-decoration: none' on the child is the right thing, unless you want potentially two underlines...
这篇关于IE7 CSS 继承不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2