W3C home > Mailing lists > Public > www-style@w3.org > March 2012

Re: :first pseudo-selector

From: Daniel Tan/BoltClock <lists@NOVALISTIC.com>
Date: Fri, 23 Mar 2012 02:51:22 +0800
Message-ID: <4F6B74AA.1060101@NOVALISTIC.com>
To: lists@NOVALISTIC.com
CC: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>, fantasai <fantasai.lists@inkedblade.net>, "www-style@w3.org" <www-style@w3.org>
On 3/23/2012 2:47 AM, Daniel Tan/BoltClock wrote:
> On 3/23/2012 2:37 AM, Marat Tanalin | tanalin.com wrote:
>>> It's necessary if you have a box with some paragraphs and don't want
>>> to have unnecessary gaps at the the end and the beginning
>>> of the box.
>> As far as I understand this part of message, it's something that I
>> thought of too.
>> Let assume we have a container with blocks inside it, and each block
>> can have margin-top and margin-bottom, and each block can contain
>> another blocks inside them, and nesting level can be arbitrary and is
>> unknown in advance.
>> It would be nice to have ability to zeroize margin-top for first
>> child, and first child of it, first child of first child of first
>> child, etc. at once. Same applies for last child.
>> Currently, AFAIK, we can only match children up to some _exact_
>> nesting level known in advance (3 in the example below):
>> .container> :first-child,
>> .container> :first-child> :first-child,
>> .container> :first-child> :first-child> :first-child {}
>> We cannot use just :first-child context selector since it would also
>> select first children of blocks that are not first children themselves.
>> So we need a sort of _recursive_ selector that matches not just first
>> of last child, but recursively matches all first-most and last-most
>> elements regardless of their nesting level.
>> A possible syntax is quite straightforward:
>> :first-child-recursive {margin-top: 0; }
>> :last-child-recursive {margin-bottom: 0; }
>> Thanks.
> I may be missing something, but how is this not fulfilled by using the
> descendant combinator rather than the child combinator?
> .container :first-child { margin-top: 0; }
> .container :last-child { margin-bottom: 0; }

And of course, right after sending that, I figure out what you mean.

The descendant combinator would match any first (and last) children, not 
only the first children of the first children as shown by your child 
combinator examples.

Daniel Tan/BoltClock
NOVALISTIC • Stellar Software Development & Design
Received on Thursday, 22 March 2012 18:51:58 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:57 UTC