[thelist] Learning CSS - what's the # for + any good tutorial s?

Steve Cook steve.cook at evitbe.com
Mon Mar 18 07:04:07 CST 2002


# is an ID selector

. is a class selector

Classes can be applied to any number of elements in a page. IDs are supposed
to only be applied once within a document (though I'm not aware of any
browsers that check for that).

More practically, IDs carry a higher weight (specificity) than classes when
"cascading". That means that the stylesheet:

<style>
p#blue {color: red;}
p.blue {color: green;}
p {color: blue;}
</style>
then setting
<p id="blue">Text with <span class="blue">different</span> colours?</p>

Will produce red text all the way, even though the class definition and the
"p" definition follow the ID definition.

As for tutorials, I dunno, but I got all of that from the O'Reilly Cascading
Stylesheets book, which I can highly recommend, even if it's a *little* old
in the tooth.

.steve

----------------------------------
   WapWarp - http://wapwarp.com
 Wap-Dev - http://www.wap-dev.net
 Cookstour - http://cookstour.org
----------------------------------



More information about the thelist mailing list