代码之家  ›  专栏  ›  技术社区  ›  Pawka

IE7CSS继承不起作用

  •  34
  • Pawka  · 技术社区  · 17 年前

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

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

    如你们所见,我创建了“无装饰”类。它应该继承h2的“a”标记样式。

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

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

    P.P.S.也有类似的例子: http://www.brunildo.org/test/inherit.html

    4 回复  |  直到 13 年前
        1
  •  55
  •   Volker E. Lee    10 年前

    没有 inherit 对于任何财产-对不起。此问题已在>=IE8。

    而您可以使用JavaScript修复程序从中复制属性 h2 a ,对两个元素应用相同的样式规则可能是最简单的:

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

    你不需要设置 通过 孩子;孩子无法删除它(模即bug)。'文本装饰:孩子身上的“无”是正确的,除非你想要 下划线。。。

        2
  •  16
  •   Carsen    15 年前

    尝试

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

        3
  •  4
  •   Stephen M. Redd    17 年前

    有一个关于继承支持的测试 here .

    您还可以尝试使用以下脚本 ie7-js “是一个JavaScript库,使Microsoft Internet Explorer的行为类似于符合标准的浏览器”

        4
  •  1
  •   Kld    12 年前

    Internet Explorer<=7个版本不支持该值 inherit direction visibility .

    推荐文章