views:

46

answers:

2

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.

+4  A: 

CSS3 has an :empty pseudo -class.

I can't see any way of doing this in pure CSS2.1.

Skilldrick
Compatibility table: http://www.quirksmode.org/css/contents.html
Pekka
Didn't realise the :empty pseudo-class existed... nice one :-) +1
ILMV
+4  A: 

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; }
Andy E