【发布时间】:2016-04-10 19:08:11
【问题描述】:
考虑这些类:
.bio-target-measure {
opacity: 1;
}
.bio-target-measure:not(.lowerThird-25.lowerThird-active):not(.lowerThird-50.lowerThird-active):not(.lowerThird-100.lowerThird-active):not(.middleThird-25.middleThird-active):not(.middleThird-50.middleThird-active):not(.middleThird-100.middleThird-active):not(.upperThird-25.upperThird-active):not(.upperThird-50.upperThird-active):not(.upperThird-100.upperThird-active):not(.bud-25.bud-active):not(.bud-50.bud-active):not(.bud-100.bud-active) {
opacity: 0 !important;
}
<div class="mark bio-target-measure upperThird-100" title="Muestra
Plaga: Oidio
ID: [4]
Tercios: ["upperThird"]" style="width:100.0%;height:100%;color:white;background-color:#6a6200;">Test</div>
还有这些 jQuery 调用:
var measures = $('.bio-target-measure');
measures.length; // evaluates to 1.
measures.is('.bio-target-measure:not(.lowerThird-25.lowerThird-active):not(.lowerThird-50.lowerThird-active):not(.lowerThird-100.lowerThird-active):not(.middleThird-25.middleThird-active):not(.middleThird-50.middleThird-active):not(.middleThird-100.middleThird-active):not(.upperThird-25.upperThird-active):not(.upperThird-50.upperThird-active):not(.upperThird-100.upperThird-active):not(.bud-25.bud-active):not(.bud-50.bud-active):not(.bud-100.bud-active)');
// evaluates to true.
var emptyMeasures = $('.bio-target-measure:not(.lowerThird-25.lowerThird-active):not(.lowerThird-50.lowerThird-active):not(.lowerThird-100.lowerThird-active):not(.middleThird-25.middleThird-active):not(.middleThird-50.middleThird-active):not(.middleThird-100.middleThird-active):not(.upperThird-25.upperThird-active):not(.upperThird-50.upperThird-active):not(.upperThird-100.upperThird-active):not(.bud-25.bud-active):not(.bud-50.bud-active):not(.bud-100.bud-active)');
emptyMeasures.length; // evaluates to 1.
但是满足opacity: 0 !important; 选择器的此类元素的不透明度(如使用 jQuery 所见)为 1. 我的 Google Chrome(47.0.2526.106,Ubuntu 15.04,64 位)浏览器使用 only 第一条规则(only 是为了澄清:不透明度为 0 的规则不存在但被覆盖:匹配中完全不存在)。
问题: :not 规则(如我所用)是有效的 CSS 选择器吗?我知道它在 jQuery 中有效,但我问的是 CSS。
【问题讨论】:
-
为不透明度使用不同的类会不会容易得多,而不是使用
:not排除所有这些元素 -
据我所知,CSS
:not只接受简单的选择器作为输入。所以,第一个本身应该写成.bio-target-measure:not(.lowerThird-25):not(.lowerThird-active)。 -
@Harry 声明的证明:jsfiddle.net/av3zjd7e/1 vs jsfiddle.net/av3zjd7e
-
@Harry 声明的进一步证明:
:not、simple selector、sequence of selectors。 -
相当于你在 jQuery 中的内容实际上要复杂得多。但是,是的,由于上述原因,归结为它只是无效的 CSS。另见:Why is my jQuery :not() selector not working in CSS?
标签: jquery css jquery-selectors css-selectors