Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple classes for an element

CSS and (X)HTML Syntax

Multiple classes for an element

by  petey  Posted    (Edited  )
To give an element multiple classes, separate the classes with spaces:
[color #cc6600]<div class="important news">...</div>
<div class="important post">...</div>[/color]

Why? It can make CSS more efficient:
[color #cc6600]<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>[/color]

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

...

[color #cc6600]<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>[/color]

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.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top