Reputation: 195
I'd like to assign a style to a HTML element - but only in the event that the tag has some contents set.
Is this possible using pure CSS? Ideally I would like to avoid JS or server-side changes to the structure of the HTML itself.
Upvotes: 8
Views: 5928
Reputation: 344575
You can do this with CSS3 by combining the :not
and :empty
pseudo-classes. For browsers that don't support both you'll need to use JS or a server-side solution.
div:not(:empty) { background-color:blue; }
Upvotes: 10
Reputation: 70849
CSS3 has an :empty
pseudo -class.
I can't see any way of doing this in pure CSS2.1.
Upvotes: 16