0

Why can't I do div:not(.wrapper2 .exception)? Ie. all divs except .wrapper2 .exception.

http://jsfiddle.net/frank_o/4swjmhtr/

HTML:

<div class="wrapper1">
    <div>
        <p>Hi</p>
    </div>
    <div class="exception">
        <p>Hi</p>
    </div>
</div>
<div class="wrapper2">
    <div>
        <p>Hi</p>
    </div>
    <div class="exception">
        <p>Hi</p>
    </div>
</div>

CSS:

div:not(.wrapper2 .exception) {
    background: blue;
    color: white;
}
Hashem Qolami
  • 93,110
  • 25
  • 145
  • 156
Mark Boulder
  • 12,610
  • 11
  • 44
  • 74

2 Answers2

3

You can't combine not() selectors like this, only one selector at a time can go in.

To select all divs except .exception inside .wrapper2:

div:not(.wrapper2) div:not(.exception)
Stephan Muller
  • 25,898
  • 16
  • 83
  • 124
3

If you are targeting all the child div's except for the last one, this is what is needed.

div > div {
    background: blue;
    color: white;
}
div.wrapper2 > div.exception {
    background: none;
    color: inherit;
}
<div class="wrapper1">
    <div>
        <p>Hi</p>
    </div>
    <div class="exception">
        <p>Hi</p>
    </div>
</div>
<div class="wrapper2">
    <div>
        <p>Hi</p>
    </div>
    <div class="exception">
        <p>Hi - not this one!</p>
    </div>
</div>
Marc Audet
  • 44,417
  • 10
  • 61
  • 82