If :not()
allowed combinators, you would be able to simply do div:not(p ~ div)
. But it doesn't, so you won't be able to use :not()
in that manner.
The selector you need will depend on your structure. In your case, if not having the p
causes the first div
to be the first child of your section
, you can use div:first-child
to make sure you select your div
s if and only if that condition is met:
div:first-child, div:first-child ~ div
If your structure does not allow such a selector to be constructed, then you will have to rely on an overriding rule as Danield suggests.