W3C home > Mailing lists > Public > www-style@w3.org > February 2015

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

From: Matt Mastracci <matthew@mastracci.com>
Date: Tue, 3 Feb 2015 22:11:53 -0700
Cc: Lea Verou <lea@verou.me>, www-style list <www-style@w3.org>
Message-Id: <08861ADB-C576-4DF0-9DB1-01789EDFE0CE@mastracci.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>

> 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;

@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

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:51 UTC