Correct notation for CSS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
yurik
Forum Newbie
Posts: 7
Joined: Tue Feb 12, 2008 3:52 pm
Location: Oushuu, Japan

Correct notation for CSS

Post 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;}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Correct notation for CSS

Post 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)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
bovermyer
Forum Commoner
Posts: 25
Joined: Tue Apr 08, 2008 9:14 am
Location: South Dakota

Re: Correct notation for CSS

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Correct notation for CSS

Post by pickle »

Really? I didn't know that. That info probably would have prevented more than one headache :banghead:
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
bovermyer
Forum Commoner
Posts: 25
Joined: Tue Apr 08, 2008 9:14 am
Location: South Dakota

Re: Correct notation for CSS

Post 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. =/
Post Reply