Re: [selectors] Proposal: :n-children() selector

> On Feb 3, 2015, at 9:52 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> 
> On Tue, Feb 3, 2015 at 8:46 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
>> With that, you could do something like:
>> 
>> @custom-selector $rest:--n-siblings($n)
>> :nth-child(1):nth-last-child($n) /self-and-siblings/ $rest;
>> 
>> So that writing `.foo:--n-siblings(3)` would become
>> `:nth-child(1):nth-last-child(3) /self-and-siblings/ .foo` after
>> expansion.
> 
> Well, I guess we don't really need new combinators; it just makes it a
> bit more convenient.  Without that, you could write it as:
> 
> @custom-selector $rest:--n-siblings($n)
> :nth-child(1):nth-last-child($n)$rest,
> :nth-child(1):nth-last-child($n) ~ $rest;
> 
> And with some ability to select parents, you could write
> :--n-children() in a similar way.

I like the idea of allowing :has() in the fast profile if it consists of nothing but “simple selectors” like sibling or direct descendant. I *think* this might allow the equivalent to the n-children(an+b of S), but it’s starting to get a little complicated to say at first glance:

@custom-selector $rest:--n-siblings($n)
$rest:nth-child(1):nth-last-child($n),
$rest:nth-child(1):nth-last-child($n) ~ $rest;

@custom-selector $rest:--n-siblings-of($n,$s)
$rest:nth-child(1 of $s):nth-last-child($n of $s),
$rest:nth-child(1 of $s):nth-last-child($n of $s) ~ $rest;

@custom-selector $rest:—n-children($n)
$rest:has( > :—n-siblings($n))

@custom-selector $rest:—n-children-of($n,$s)
$rest:has( > :—n-siblings-of($n,$s))

Received on Wednesday, 4 February 2015 05:12:26 UTC