Page 1 of 1

Correct notation for CSS

Posted: Tue Apr 08, 2008 9:37 am
by yurik
I would like to know the difference if any for these 3 CSS lines: the ".", the "#" and without anything. I don't know if its relevant but I'm programming in xhtml.

.css{cssdata;}
css{cssdata;}
#css{cssdata;}

Re: Correct notation for CSS

Posted: Tue Apr 08, 2008 9:49 am
by pickle
.className allows you to define the styles for a particular class.
elementName allows you to define/override the default styles for a particular element (such as <strong>, <form>, etc)
#idName allows you to define the styles for a particular element with the id "idName" (of course, substituting in your own ID where appropriate)

Re: Correct notation for CSS

Posted: Tue Apr 08, 2008 10:52 am
by bovermyer
Additionally, # (id name) overrides take precedence over . (class name) overrides, and both take precedence over element name overrides. So, if you define an id name #whatever before a class name .whatever in your CSS, the #whatever will still override the .whatever styles even though it comes before it.

CSS is fun that way.

Re: Correct notation for CSS

Posted: Tue Apr 08, 2008 11:03 am
by pickle
Really? I didn't know that. That info probably would have prevented more than one headache :banghead:

Re: Correct notation for CSS

Posted: Tue Apr 08, 2008 11:54 am
by bovermyer
pickle wrote:Really? I didn't know that. That info probably would have prevented more than one headache :banghead:
Aye, it was the cause of many a headache for me too before I finally figured it out. =/