CSS Parent/Ancestor Selector [duplicate]
You can use has(): div:has(> .test) { /*styling, for div, not .test …*/ } In CSS there is an :empty selector that allows you to match empty elements, you can negate the effect with :not selector. div:not(:empty) { // your styles here } However I’m not sure if all browsers support this.