Reputation: 107
I have the following test code:
<html>
<head>
<style type="text/css">
#test, .random-class { font-weight:bold; }
#test, .random-class:not('.another-class') { color:red; }
</style>
</head>
<body>
<div id="test">hello world</div>
</body>
</html>
This produces the following output:
In my understanding, hello world should be bold and red, but it's only bold. I expected the second rule to affect
What am I missing here? Why is the second rule not applied?
Upvotes: 0
Views: 161
Reputation: 6522
The second rule is not applied because there's an error in your sytax, which breaks the entire rule, not just the selector that is broken.
:not(.abother-class)
is teh correct syntax (without the quotes.
If you separated your rules into two you'd get your desired effect, as would fixing the error e.g. either of these two solutions should work:
#test {color: red}
.random-class:not('.another-class') {color: red} /*This is still broken, but doesn't effect the above rule now*/
or
#test, .random-class:not(.another-class) {color: red} /* fixed*/
Upvotes: 1
Reputation: 3699
You don't need the quotes around the class in your :not()
selector, if you change it so it becomes:
#test, .random-class:not(.another-class)
{
color:red;
}
It will work as you expect it to
Take a look here for a demo
Take a look here for the docs on the :not()
selector
Mentioned by @KWeiss in the comments:
Specifically the quotes are making the selector invalid so the rule is not applied
Hope this helps!
Upvotes: 3
Reputation: 109
You dont need to use ' in :not
#test, .random-class { font-weight:bold; }
#test, .random-class:not(.another-class) { color:red; }
Upvotes: 1