【问题标题】:IE 7 not using the most specific CSS ruleIE 7 没有使用最具体的 CSS 规则
【发布时间】:2011-08-09 23:00:51
【问题描述】:

我想将所有th 元素的样式设置为相同(黑色背景上的白色文本),除了一些不需要这种格式的用法 - 在这种情况下,我将no-headers 类添加到表格元素.

th {background-color: #000000; color:#FFF;}
table.no-headers th {color:inherit; background-color:inherit ;border:inherit; } 

如果您需要,这里有一些示例标记

<table><tr><th>This has a black bground</th></tr></table>
<table class="no-headers"><tr><th>This inherits bground from parent</th></tr></table>

这在 IE 8/9 和 FF 和 Chrome 中可以正常工作,但在 IE 7 中不行。 IE 7 不会使用第二条规则——尽管它更具选择性。
事实上,我已经尝试了各种方法来解决这个问题 - 都无济于事。

我也尝试在第 th 元素上添加 no-headers 类

th {background-color: #000000; color:#FFF;}
th.no-headers {color:inherit; background-color:inherit ;border:inherit; } 

<table><tr><th class="no-headers">This inherits bground from parent</th></tr></table>

即使这样也不起作用 - 我感觉自己在做一些非常明显愚蠢/错误的事情 - 但在其他浏览器中它又可以正常工作!

非常感谢任何帮助。

【问题讨论】:

标签: css internet-explorer-7 css-selectors


【解决方案1】:

IE7 无法识别 inherit 关键字(除了一些不起眼的属性)。

最好的办法是手动指定默认颜色。

【讨论】:

  • 或者说粗话:别担心,你什么都没做。 IE7 是最愚蠢的。
【解决方案2】:

根据这篇 SO 帖子:IE7 CSS inheritance does not work IE 直到 IE8 才支持继承。因此,您必须专门指定颜色、背景和边框。

【讨论】:

    【解决方案3】:

    IE7 不支持样式继承。这是在 IE8 中引入的。

    见:IE7 CSS inheritance does not work

    这不是一个大问题,因为 IE8 是 IE7 的通用升级版,与 IE9 不同,IE9 仅适用于 Windows NT6 及更高版本。

    【讨论】:

      猜你喜欢
      • 2014-01-17
      • 2012-01-31
      • 2014-02-10
      • 2012-03-24
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多