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?
The :empty CSS pseudo-class represents any element that has no children.
The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.
In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.
: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 */ }
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; }
Codepen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With