W3C home > Mailing lists > Public > www-style@w3.org > July 2009

Re: [css3-selectors] No way to select preceding sibling element

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 13 Jul 2009 21:15:49 -0500
Message-ID: <dd0fbad0907131915k3f1564b1gcb76692d1c19bf91@mail.gmail.com>
To: Aryeh Gregor <Simetrical+w3c@gmail.com>
Cc: Paul <paul@scriptfusion.com>, www-style@w3.org
On Mon, Jul 13, 2009 at 7:38 PM, Aryeh Gregor<Simetrical+w3c@gmail.com> wrote:
> On Mon, Jul 13, 2009 at 7:59 PM, Tab Atkins Jr.<jackalmage@gmail.com> wrote:
>> As an addendum to my previous email, I'll note that we have some
>> selectors in CSS that are just as bad as some of the reverse
>> combinators.  :last-of-type, for example, is essentially equivalent to
>> a reverse ~ ("p:last-of-type" and "p [reverse~] p" are identical in
>> effect).
>
> No, they aren't, AFAICT.  In <div><p>a<p>b<p>c</div>, p:last-of-type
> matches only the final p, while p ~~ p (using ~~ for [reverse~] for
> readability) matches the first two.  p:last-of-type is the same as
> p:not(p ~~ p).

Aw dang, you're right.  That's another strike against reverse
combinators - they're hard to use!  ^_^  I think I would have gotten
this right had I used the :has() pseudoclass.  Then :last-of-type is
p:not(:has(~p)), which looks a lot more understandable than
p:not(p~~p), at least to me.

> In principle :last-of-type (and :only-child, etc.) could require that
> the whole page's style be recomputed.  E.g., you could have
>
> <body>
> <div>...whole page...</div>
> <div>Minor footer nobody cares about</div>
> </body>
>
> and body > :only-child, or body > :last-of-type, or whatever.  But
> they're narrower and so likely to be used less, I guess.  Plus they're
> essential for some styling.

Yup, I noted that the reverse combinators can produce effects
arbitrarily high in the ancestor tree at times, and as those
pseudoclasses basically employ reverse-combinator effects, they
inherit that danger as well.

~TJ
Received on Tuesday, 14 July 2009 02:16:48 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:19 GMT