CSS: Style applied to a combination of classes?

Posted by Eli on Stack Overflow See other posts from Stack Overflow or by Eli
Published on 2010-03-16T00:25:08Z Indexed on 2010/03/16 0:29 UTC
Read the original article Hit count: 641

Filed under:
|

Hi All,

I'm not sure this is possible, but is there a syntax to be used in CSS when you want to style an element based on the combination of classes applied to it?

I understand that I can check an element with jQuery or something and change it's style based on the classes it has, but is there a pure CSS way to do this?

For example, if I have a class for bold and green:

.bold_green { color:green; font-weight:bold; }

And a class for bold and blue:

.bold_blue { color:green; font-weight:bold. }

Now, say I am using jQuery to add and remove classes dynamically and want any element that has both classes to turn italic pink.

Something like:

.bold_green AND .bold_blue { color:pink; font-style:italic; }

Or, if I want to style an element that has aclass, and is a descendant of another element that has another class?

Something like:

.bold_green HAS_CHILD .bold_blue { color:black; background-color:yellow; }

Thanks!

© Stack Overflow or respective owner

Related posts about css-selectors

Related posts about css