Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My browser does not match my CSS (but jQuery does)

Consider these classes:

.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: [&quot;upperThird&quot;]" style="width:100.0%;height:100%;color:white;background-color:#6a6200;">Test</div>

And these jQuery call:

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.

But the opacity for such element, which satisfies the selector for opacity: 0 !important; (as it was seen using jQuery), is 1. My Google Chrome (47.0.2526.106, Ubuntu 15.04, 64bits) browser uses only the first rule (the only is to clarify: rule with opacity 0 is not present-but-overriden: is totally absent in the match).

Question: is the :not rule (as I used it) a valid CSS selector? I know it works in jQuery, but I ask about CSS.

like image 839
Luis Masuelli Avatar asked Sep 25 '22 18:09

Luis Masuelli


1 Answers

Following from @Harry's comment, you cannot have combined selectors in your :not(). (Evidence provided by @TJCrowder: :not, simple selector, sequence of selectors)

In a case like this, you will need to rework your logic:

.bio-target-measure.lowerThird-25:not(.lowerThird-active),
.bio-target-measure.lowerThird-50:not(.lowerThird-active),
...

This can be made a lot easier using LESS or a similar higher-level version of CSS:

.bio-target-measure {
    &.lowerThird-25, &.lowerThird-50, &.lowerThird-100 {
        &:not(.lowerThird-active) {
            opacity: 0 !important;
        }
    }
    /* define similar blocks for middleThird and upperThird */
}

The above will compile into the complicated selector suggested in the first code block, while being much easier to read.

like image 187
Niet the Dark Absol Avatar answered Oct 03 '22 02:10

Niet the Dark Absol