【问题标题】:CSS :not workaround for Internet ExplorerCSS:不是 Internet Explorer 的解决方法
【发布时间】:2011-08-13 19:31:40
【问题描述】:

following example 在 Firefox 4 中有效,但在 Internet Explorer 8 中无效:

HTML:

<div class='first'>A</div>
<div>B</div>
<div>C</div>

CSS:

div:not(.first) {
    color: red;
}

你会建议什么解决方法让它在两种浏览器中都能正常工作?

【问题讨论】:

  • 不是您问题的答案,但在上面的代码中您可以使用:first-child 选择器而不是class='first'
  • IE9.js 似乎在 IE 中实现了这个选择器...

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


【解决方案1】:

你为什么不能这样做?:

div {
    color: red;
}
div.first {
    color: inherit;/* or whatever color you want*/
}

这并不是真正的:not() 解决方法,但据我所知,它适用于您的示例。如果您没有该课程,您也可以随时使用:first-child。

Demo

【讨论】:

    【解决方案2】:

    不完美但有效:

    div {
       color: red;
    }
    
    div.first {
       //some other colour
    }
    

    编辑:或者 madmartigan 所说的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 2013-11-28
      • 2013-01-12
      • 2016-02-19
      • 2019-10-15
      • 1970-01-01
      相关资源
      最近更新 更多