Reputation: 48476
I want to style code
elements that are not inside a
tags.
What is the best approach to accomplish this?
code:not(a code)
doesn't seem to work at all, at least on Chrome, even though it seems like it should
I can't get it to work from the console either.
Are there any other css-only approaches I could use for this?
Upvotes: 124
Views: 149640
Reputation: 89
This works too:
h1:not(.original-style h1){
/* This will apply for every h1 tag **not**
in any .original-style at any level.
*/
}
Upvotes: 8
Reputation: 714
Actually, you should be able to use your code 🤔, or you could use the wildcard character to select all elements to not be selected
code:not(a *) {
font-weight: bold;
}
Upvotes: 40
Reputation: 219920
:not
does not support combinator selectors.
If we're talking about its direct parent:
:not(a) > code
Otherwise there's no way to do this in CSS. You'll have to override it:
code {
/* some styles */
}
a code {
/* override previous styles */
}
Upvotes: 164