Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
CSS

Can I use more than one/multiple class for an element? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5551" title="Pages that link to Can I use more than one/multiple class for an element?" rel="nofollow" >Can I use more than one/multiple class for an element?\

The simple answer is yes you can use multiple classes - the trick is using this correctly. To quote Slime:

quote:
There are a few errors in DL's post that should be noted:

<div class="8877" class="shoppingCartItem"> displays item in side bard shopping cart style</div>

This is incorrect; the correct syntax is:

<div class="8877 shoppingCartItem"> displays item in side bard shopping cart style</div>

(Note that the multiple classes are separated by spaces.)

Secondly, neither an ID nor a class may begin with a number. So 8877 is neither a valid ID nor a valid class name. Change it to something like "itemNumber8877" or something.



However, you can only have one id:

quote:
while the id="" attribute can only have one value, and that value must be different from all other IDs in the page, the class="" attribute can have *multiple, space separated* values. For instance:

.happy {font-style:italic; font-color:#F88;}
.evil {font-family:FontOfEvilness;}
...
<p class="happy">I'm the good guy</p>
<p class="evil">I'm the bad guy</p>
<p class="evil happy">I'm the bad guy after eating the good guy</p>




-----------------------------
Relevant threads:

class VS id what is the difference

some questions on css

-----------------------------
Relevant links:

CSS Multiple Classes on Elements

Using Multiple CSS Classes on Elements

-------------------------
Relevant FAQs:

What is the difference between an ID and a class in CSS?

______________________
Emperor

(Added by: Emperor on Sat 08-Feb-2003)

(Edited by: Emperor on Sat 08-Feb-2003)

« BackwardsOnwards »

Show Forum Drop Down Menu