INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

CSS and (X)HTML Syntax

Multiple classes for an element by petey
Posted: 18 Dec 03

To give an element multiple classes, separate the classes with spaces:
<div class="important news">...</div>
<div class="important post">...</div>


Why? It can make CSS more efficient:
<style>
div.news{border:1px solid orange;padding:.5em;background:#cdc;}
div.post{border:1px dotted black;padding:.5em;background:#eee;}
.important{font:bold 120% sans-serif;color:red}
</style>


For reference, the corresponding inefficient CSS might look like this:
<div class="importantnews">...</div>
<div class="importantpost">...</div>


...

<style>
div.news{border:1px solid orange;padding:.5em;background:#cdc;}
div.post{border:1px dotted black;padding:.5em;background:#eee;}
div.importantnews{border:1px solid orange;padding:.5em;background:#cdc; font:bold 120% sans-serif;color:red}
div.importantpost{border:1px dotted black;padding:.5em;background:#eee; font:bold 120% sans-serif;color:red}
.important{font:bold 120% sans-serif;color:red}
</style>


This technique is stated in the W3C spec:
http://www.w3.org/TR/html4/struct/global.html#h-7.5.2

Supporting browsers reportedly include, but are not limited to:
IE 5.0, 5.5 and 6, Mozilla 1.4 and 1.5 and Firebird 0.7, Opera 7, IE for Mac and Safari for Mac.

Back to HTML, XHTML & CSS FAQ Index
Back to HTML, XHTML & CSS Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close