CSS Tip: Using Multiple Classes

Mar 13 2009
Posted by Mark

You probably already know that you can add multiple classes to elements in HTML.

Example:


<div class="Post First">...

But, did you know that you can string them together in your CSS selectors?

Example:


div.Post.First{ color: red }

You can also use this trick to combine classes and IDs.

Example:


<div id="First" class="Large">...

And the CSS selector,


div#First.Large{ font-size: 150% }

A word of caution, this trick does not work in IE6. But then, if we limited ourselves to what worked in IE6, we’d never get anywhere.

Hope you find this to be useful.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply