PDA

View Full Version : Using punctuation in DIV and .class names



gnubler
09 Aug 2006, 09:33 AM
Can someone steer me in the right direction? I have been using underscores and dashes in my CSS selector names all along without any problems, but am now reading a book by Zeldman that says underscores aren't recognized in CSS2 and dashes are illegal.

I spent five minutes Googling this and didn't find exactly what I wanted - can someone link me or spell out the rules on file names & punctuation/numbers?

Wickham
09 Aug 2006, 10:04 AM
I have been told that dashes are illegal in some scripts, but not css2 as far as I know.

Re selectors, I found this regarding CSS1 which says underscores are illegal:-
http://lists.evolt.org/archive/Week-of-Mon-20020311/106623.html

Re CSS2 selectors see this:-
http://www.nic.fi/~tapio1//Teaching/Valitsimet1.php3
You can use also number + hyphen, but you can't start with them.
The name must start with a normal letter (a-z,A-Z). Accepting the underscore (_) has been afterward added into CSS2.

See also the official CSS2 changes:-
http://www.w3.org/TR/CSS21/changes.html
The underscore character ("_") is allowed in identifiers.

Note the different way browsers render it:-
http://www.thefixor.com/help/cssfaq.php

-------------------------
I believe underscores are still valid in urls but undesirable as many links have an underline which obscures the underscore. There have been situations where someone writes down or reads out a url to a colleague assuming a space which is really an underscore and the url when later used is no good.

Both should be avoided in my view.

I found this interesting, (it didn't say either is invalid):-
http://www.simoncox.com/mt3/2006/06/dashes_vs_underscores.php