I'm trying to select all code
elements except the one that's a descendant of the pre
element using a :not(~)
selector. This post has a very similar answer but I'm having a hard time figuring out my problem.
<body>
<div><code>Div Code</code></div>
<pre><code>Pre Code</code></pre> <!-- Exclude only this -->
<Code>Body Code</Code>
</body>
This selector using :not(~)
doesn't seem to work.
code:not(pre code) {
color:red;
}
The code
selector selects all three, and pre code
selects only the 2nd one, so shouldn't joining them using :not
produce all three except the 2nd one?
What could be wrong here?
I could use a selector other than the :not(~)
but it fits the best for my use-case since code
element can be nested in other elements and I want to exclude only the descendants of pre
.
Thanks in advance.