Re: Recommended practice on selector compatibility

On Tue, 3 Dec 2002, Christian Roth wrote:
> 
> How does one best formulate the selector for a class named 'heading 1'?

Classes are space separated lists of words, so that is actually two
classes, "1" and "heading". You can match it using any of:

   .heading.1
   .1.heading
   [class=~"heading"][class=~"1"] /* CSS2 only */
   [class=~"1"][class=~"heading"] /* CSS2 only */

You can also ignore the semantics of the class attribute and match the
entire thing as one string using:

   [class="heading 1"] /* CSS2 only */

...but that wouldn't match the semantically identical class="1 heading".

> How do I tell a CSS3 parser that \0020 is a CSS2 conformant, maximum 4
> char escape sequence and the trailing '1' is the next literal
> character?

By following the escape with a space (which is ignored), as in:

   "\0041 B"

...which is identical to:

   "AB"


> Also, the .classname shorthand seems only to be defined for HTML
> documents

To be precise, "." is defined for any language which explicitly states
that it has an attribute that this selector applies to, which so far
includes, to the best of my knowlegde, HTML, XHTML, SVG, MathML, and XUL.


> What I have thought of would be something like
> 
>   .heading\00201, *[class=heading\0000201] { ... }
> 
> Is this correct CSS and, more specifically, is this a viable solution?

This will not be recognised by a CSS1 UA, since it doesn't recognise the
bit after the comma and therefore ignores the entire rule.

-- 
Ian Hickson                                      )\._.,--....,'``.    fL
"meow"                                          /,   _.. \   _\  ;`._ ,.
http://index.hixie.ch/                         `._.-(,_..'--(,_..'`-.;.'

Received on Tuesday, 3 December 2002 21:17:27 UTC