Re: Selectors 4 and Variables

On 09/30/2011 05:03 PM, Tab Atkins Jr. wrote:
>
> I thought it was generally agreed long ago that the best approach was
> to use :has() rather than a marker in the selector.  It's more general
> and allows more types of things to be expressed.

It wasn't *generally* agreed. It was only agreed by some people.

> Basically, the subject indicator is exactly equivalent to a :has()
> pseudo limited to the end of the selector:
>
> foo $bar baz {...} == foo bar:has(baz) {...}
>
> However, :has() can be placed anywhere in the selector, and so allows
> more powerful selections:
>
> label:has(:checked) + section>  p {...}

The limitation to a single branch here is intentional, due to
implementation concerns.

If I were going to do branching, I'd expand :matches() to take full
selectors rather than only compounds.

label:matches(!#$%? :checked) + section > p { ... }

This has the advantage that selectors work the same whether they
are within or without the pseudo-class argument. There's neither
implicit nor dangling combinators, as you have with :has().

~fantasai

Received on Saturday, 1 October 2011 03:16:24 UTC