Previous Message
Next Message

Re: [css-d] IE comma hack?

Sent by John Lewis on 21 February 2003 08:08


Big wrote on Friday, February 21, 2003 at 1:14:03 AM:

> I was reducing a bug, and noticed that if I have a selector with a
> following comma, but no further selectors, then IE applies the style
> block to that element, but Moz and Opera do not.

> Is this valid?

>From the CSS2 prose on grouping selectors[1]: "When several selectors
share the same declarations, they may be grouped into a
comma-separated list."

Compare to the prose for grouping declarations[2]: "The first thing to
notice is that several declarations are grouped within a block
enclosed by curly braces ({...}), and separated by semicolons, though
the last declaration may also be followed by a semicolon."

Since the first doesn't mention an exception to the rule, I assume the
rule stands as it's written. This is bolstered by how the second is
written, with an explicit exception that the last declaration may be
followed by a semicolon.

Nothing isn't a selector, and whitespace isn't a selector (to my
knowledge), so the selector is invalid and should be ignored. At
*best* it's a bad idea because it may cause problems in the future,
even if it is technically valid.

Someone who understands the CSS grammar[3] could probably give you a
definite answer.

Even if it does invalidate your style sheet, only the associated
declaration block should be ignored. So you can use it to trick stupid
browsers if validation isn't important to you; although there are
probably valid ways of accomplishing the same thing.

[1] http://www.w3.org/TR/REC-CSS2/selector.html#grouping
[2] http://www.w3.org/TR/REC-CSS2/intro.html#q1
[3] http://www.w3.org/TR/REC-CSS2/grammar.html

-- 
John
Previous Message
Next Message

Message thread: