W3C home > Mailing lists > Public > www-style@w3.org > September 1999

Re: selector matching question

From: Bert Bos <Bert.Bos@sophia.inria.fr>
Date: Wed, 22 Sep 1999 23:28:24 +0200 (MET DST)
To: Ranjit Singhe <ranjit_singhe@mail.com>
Cc: www-style@w3.org
Message-ID: <14313.18576.885231.999058@www43.inria.fr>
Ranjit Singhe writes:
> hello,
> 
> this (i hope) is not a css writing question. it is more a selector matching
> question.  i've attached a simple html file that uses styles.
> 
> it has to do with ancestral resolution.  when you look at the html it should
> be fairly clear what i'm trying to do.
> 
> for a while now i've been using gecko to test my resolution cases, so try it
> in gecko; hence this post. :)
> 
> here's my question (the atmt. reflects this case):
> 
> if an element (SPAN) has two ancestors of the same name (OL)
> 
> e.g.

...+-- DIV
...+-- DIV
........+-- OL
.............+-- DIV
..................+-- DIV
........................+-- OL
.............................+-- SPAN
...................................+-- (Text)

> and there are two styles in order as follows:
> 
> DIV > DIV OL SPAN { color: blue }          --- (1)
> DIV + DIV OL SPAN { color: magenta }       --- (2)
> 
> what is the color of (Text) ??
> 
> i think it should be magenta 'cos:
> a. OL parent of SPAN is found
> (1) succeeds
> (2) fails
> b. because 2 failed, we look further up and find
> OL parent of DIV
> (1) fails
> (2) succeeds
> c. because 1 failed, we look further up and find no
> more ancestors with name OL
> 
> because (2) is chronologically after (1), the text should be magenta 'cos it
> beats (1) on the collisions.  (i say this 'cos the specificity (= 4) and
> owner (= author) are the same.)
> 
> even if (1) and (2) had succeeded at stage b., (2) would win because of the
> chronology contest.
> 
> am i right???

I believe you are.

With the new selectors in CSS2 it has become necessary to test
multiple ways to match a selector against a tree of elements. There is
no rule that says that the OL ancestor of SPAN must be the nearest
ancestor.


Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/INRIA
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Wednesday, 22 September 1999 17:29:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:00 GMT