Re: target-attr() and /reference combinator/ proposals

On Mon, 24 Jan 2000, Sjoerd Visscher wrote:

>    C A /attr/ B
> would match an element B that is pointed to by an element A, and A
> has an ancestor C.

Right.

>    C (A /attr/ B)
>    A /attr/ (C B)
> would match an element B that is pointed to by an element A,
> and B has an ancestor C.

Ooh. Nasty. I hadn't even remotely thought of that!

Yeah, it would seem that we need scoping rules for that selector. (Or
not. See below.)


>    A:: /attr/ (C B)
>    A:matches(/attr/ (C B))
> would match an element A that points to an element B, and B has an
> ancestor C.

Yup, with scoping again.


>    (C:: A) /attr/ B
>    C:matches(A) /attr/ B
> would match an element B that is pointed to by an element C, and C
> has an descendant A.

Yup.


>    (C:: A):: /attr/ B
>    (C:: /attr/ B):: A
>    C:matches(A):matches(/attr/ B)
>    C:matches(/attr/ B):matches(A)
> would match an element C that points to an element B, and C has an
> descendant A. (Here :matches() wins in clarity!)

Yup. (And yup!)


>    C:: A /attr/ B
>    C:matches(A /attr/ B)
> would match an element B that is pointed to by an element A, and A
> has an ancestor C.

No, it would match an element C that has a descendant A that points to
an element B.


> And indeed, :matches() is clearer than ::

Yes... Scoping looks rather useful, too.

I think for 'simple' cases :matches() is better than :: (or :select),
in particular because it copes with many more cases without explicit
scoping. For more complex cases, scoping is needed:

   A:matches(/attr/ (C B))
   C (A /attr/ B)
   A /attr/ (C B)
   A /attr/ (C /attr/ B)

...or the equivalent of :matches() but starting at the document root,
as in (equivalents to the previous four examples):

   A:matches(/attr/ B:matched(C))
   C B:matched(A /attr/)
   A /attr/ B:matched(C)
   A /attr/ B:matched(C /attr/)

Hmm. I like it. :-)


> although I still think pseudo-elements should be different from
> pseudo-classes, mainly becuase pseudo-elements can appear only once
> in a selector.

Right. (Lest anyone is confused, :matches() is a pseudo-CLASS. The
discussion here is about making pseudo-elements like :before be more
distinct from pseudo-classes. See [1]).


> In fact, pseudo-elements have nothing to do with selecting, it's
> about creating. I would like to see something like:
> 
> selector {
>   color: green;
>   @pseudo-element before {
>     content: "[";
>   }
>   @pseudo-element after {
>     content: "]";
>   }
> }
> 
> That's also because different pseudo-elements will be used together
> with the same selector at the same time. (often both 'before' and
> 'after' will be used f.e.)

Interesting, but I think it's probably too late to change the syntax
that radically. The above cuts deep into how pseudo-elements are
treated, and there are already working implementations that have had
bugs wrung out of them, e.g. Mozilla.

============
[1]: From a proposal I'm writing [2]:

  WHY :SELECTED IS A BAD THING AND WE SHOULD SEPARATE PSEUDO CLASSES
  FROM PSEUDO ELEMENTS

    What is :selected ? Is it a pseudo-class or pseudo-element?

    The answer is 'neither'. It is an entirely new type of selector
    which simply changes the subject of the selector chain. Thus it is
    inconsistent with the rest of the selectors draft. (I propose that
    we use :matches() instead. See footnote [A] below.)
    
    Secondly, what is :-foo-bar ? Is it a pseudo-class or
    pseudo-element? The "-foo-" prefix is a mechanism designed by the
    working group to flag extensions in a forward-compatible way.
    However, implementations with 'open-ended' engines have no way of
    knowing which it is supposed to be, pseudo-class or -element, and
    thus have no easy way of dealing with them internally.

    Thus I propose that pseudo-elements be changed to use the ::
    prefix instead, as I have used above.

      ::before

    ...and so forth. This will also hopefully make people think more
    carefully about whether something is a pseudo-class or -element,
    and they may even realise that things like :selected are neither
    one nor the other...

[2] http://www.bath.ac.uk/%7Epy8ieh/internet/wwwstyle/selectors.txt

-- 
Ian Hickson                            ("`-''-/").___..--''"`-._   
http://www.bath.ac.uk/%7Epy8ieh/        `6_ 6  )   `-.  (     ).`-.__.`)
                                        (_Y_.)'  ._   )  `._ `. ``-..-' fL
Member, Mozilla Quality Assurance     _..`--'_..-_/  /--'_.' ,'
Browser Standards Compliance Team    (il).-''  (li).'  ((!.-'    

Received on Monday, 24 January 2000 18:13:12 UTC