Multiple class syntax

Okay, I’ve known for a long time that you could assign multiple classes to an element, like so:

<div class="large red">Some text</div>

Then I could reference code css to define red styles and large styles.

.large {font-size:2em}
.red {color:red}

And the text would be large and red. All good. But what I wanted to be able to define was a style that only applied if both classes were on an element. And I’ve been going along not realizing that the syntax was available. How could I have missed that in the book (it was on page 34)? But I did. So, maybe someone else has, too. Here is the syntax.{border:1px solid black}

And so my div text, above, will be large, red, and have a black border. The syntax is to just butt those class definitions up next to each other with no space in between them. Simple. Happy coding!

CAVEAT: This does not work in IE 6. So, if you have the luxury of not having to code for that old browser, or if you are able to put Dean Edwards’ IE7 script on your server, you can use this syntax.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s