Re: Can identifier names start with a hyphen?

Please disregard what I wrote before.

I see now that the prose in section 4 simply expresses contraints that
are more restrictive than the grammar defined in appendix G

Jesse


--- Jesse McCarthy <w3c@jessemccarthy.net> wrote:

> 
> > > [spec source: http://www.w3.org/TR/CSS21/syndata.html]
> > > Only properties, values, units, pseudo-classes, pseudo-elements,
> > > and at-rules may start with a hyphen (-); other identifiers (e.g.
> > > element names, classes, or IDs) may not.
> > > [/spec]
> > > 
> > > This seems to contradict the previous statement and says that IDs
> > > like "-abc" are invalid.
> > 
> > This is intended to further restrict the definition for "other
> > identifiers" to something stricter than that for identifiers in
> > general. Considering that this sentence immediately follows the
> > previous one, I think it's reasonably clear that it's adding
> > further restrictions to the previous sentence.
> 
> The prose from 4.1.3 (quoted above) that says that IDs may not start
> with a hyphen seems to be at odds with the grammar expressed in
> Apendix
> G.
> 
> simple_selector
>   : element_name [ HASH | class | attrib | pseudo ]*
>   | [ HASH | class | attrib | pseudo ]+
>   ;
>   
> That says that a selector can start with a HASH, which is defined as:
> "#"{name}
> 
> {name} is defined as:
> {nmchar}+
> 
> {nmchar} is defined as:
> [_a-z0-9-]|{nonascii}|{escape}
> 
> According to that expression, couldn't an ID used in a selector start
> with a hyphen, a digit, or a hyphen followed by a digit?  And it
> seems
> that class selectors are defined such that the class name could start
> with a hyphen, but not a digit or a hyphen followed by a digit.
> 
> Do I have that right?
> 
> Jesse
> 
> 
> --- "L. David Baron" <dbaron@dbaron.org> wrote:
> 
> > On Thursday 2006-03-16 17:57 -0500, Vlad Alexander wrote:
> > > 
> > > Sorry if this has already been asked. Can identifier names
> (classes
> > > and IDs) start with a hyphen?
> > 
> > Identifiers in general and classes and IDs specifically are two
> > different things.
> > 
> > > [spec source: http://www.w3.org/TR/CSS21/syndata.html]
> > > In CSS 2.1, identifiers  (including element names, classes, and
> IDs
> > in selectors) can contain only the characters [A-Za-z0-9] and ISO
> > 10646 characters U+00A1 and higher, plus the hyphen (-) and the
> > underscore (_); they cannot start with a digit, or a hyphen
> followed
> > by a digit.
> > > [/spec]
> > 
> > This describes the general rules for identifiers, and gives some
> > examples of things that are identifiers.
> > 
> > > That's clear. IDs like "-abc" are okay but "-0abc" are not. The
> > spec then reads:
> > > 
> > > [spec source: http://www.w3.org/TR/CSS21/syndata.html]
> > > Only properties, values, units, pseudo-classes, pseudo-elements,
> > and at-rules may start with a hyphen (-); other identifiers (e.g.
> > element names, classes, or IDs) may not.
> > > [/spec]
> > > 
> > > This seems to contradict the previous statement and says that IDs
> > like "-abc" are invalid.
> > 
> > This is intended to further restrict the definition for "other
> > identifiers" to something stricter than that for identifiers in
> > general.
> > Considering that this sentence immediately follows the previous
> one,
> > I
> > think it's reasonably clear that it's adding further restrictions
> to
> > the
> > previous sentence.
> > 
> > > I ran the following 2 rules through the W3C CSS validator and
> > according to the validator, both are valid:
> > > 
> > > #-abc {color:red}
> > > #-0abc {color:red}
> > 
> > The validator is not a reference implementation, and it's not even
> a
> > particularly well-maintained implementation, so that's pretty much
> > irrelevant.
> > 
> > -David
> > 
> > -- 
> > L. David Baron                                <URL:
> > http://dbaron.org/ >
> >            Technical Lead, Layout & CSS, Mozilla Corporation
> > 
> 
> 
> 
> 
> 
> 
> 
> 

Received on Friday, 17 March 2006 01:13:39 UTC