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;}
Correct notation for CSS
Moderator: General Moderators
Re: Correct notation for CSS
.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)
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.
Re: Correct notation for CSS
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.
CSS is fun that way.
Re: Correct notation for CSS
Really? I didn't know that. That info probably would have prevented more than one headache 
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Correct notation for CSS
Aye, it was the cause of many a headache for me too before I finally figured it out. =/pickle wrote:Really? I didn't know that. That info probably would have prevented more than one headache