If anyone still needs this, I found this answer . Based on it and on :not pseudo-class, the initial requirement can be accomplished using something like:
div:not(:has(+ .idontwant)) .iwant {
...
}
This approach has an advantage over the general sibling combinator: It also matches backwards, meaning something like:
<div>
<div class="idontwant" />
<div class="iwant" />
</div>
(so if you have the .idontwant
element first -> case which would be ignored by the general sibling combinator)
Explanation:
div:has(+ .idontwant)
would match any div
that has a direct sibling with the class idontwant
div:not(:has(+ .idontwant))
matches any div
that doesn't have a direct sibling with class idontwant
- All is left to do is search in the div that doesn't have a direct sibling with class
idontwant
for the class we want.
The selector is quite weird and big, but does the job, and I think there are (specific) cases where is quite needed.