- From: Christoph Päper <christoph.paeper@crissov.de>
- Date: Tue, 17 Aug 2010 11:31:34 +0200
- To: "www-style@w3.org list" <www-style@w3.org>
Currently :nth-child(an+b) etc. only match anything if the argument, an+b, evaluates to a positive value. | The :nth-child(an+b) pseudo-class notation represents | an element that has an+b-1 siblings before it in the document tree, | for any positive integer or zero value of n, and has a parent element. In a procedural language this declarative statement became something like for (n = 0; a*n+b ≤ children.count; n++) if (a*n+b > 0 and child.index == a*n+b) then style or for (i = b; i ≤ children.count; i += a) if (i > 0 and child.index == i) then style I assume it helps implementation optimization that authors have to resort to :nth-last-child() if they need to count from the end. If this is not the case, would it break any other use case to define :nth-child(-1) as matching the last child (and other negative values accordingly)? for (i = b; i ≤ children.count; i += a) if (i > 0 and child.index == i) then style if (i < 0 and child.index == i + children.count + 1) then style This isn’t strictly necessary for existing selectors, but imagine we wanted to introduce new pseudo classes or elements to match, for instance, auto-generated columns or lines of text. Instead of introducing a whole bunch of pseudo classes, ‘::column(an+b)’ and ‘::line(an+b)’ would suffice. It would further improve stylesheet readability then to add shorthands ‘first' (1) and ‘last’ (-1) besides ‘odd’ (2n+1) and ‘even’ (2n), and just maybe even ‘any’ (n) and ‘none’ (0).
Received on Tuesday, 17 August 2010 09:32:08 UTC