- From: Marat Tanalin | tanalin.com <mtanalin@yandex.ru>
- Date: Thu, 22 Mar 2012 22:56:06 +0400
- To: "lists@NOVALISTIC.com" <lists@novalistic.com>
- Cc: fantasai <fantasai.lists@inkedblade.net>,"www-style@w3.org" <www-style@w3.org>
22.03.2012, 22:51, "Daniel Tan/BoltClock" <lists@NOVALISTIC.com>: > 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. Exactly. HTML example for even more clarity: <div class="container"> <div> <div>First-child of first-child</div> <div></div> </div> <div> <div>First-child, but not first-child of first-child. This element is matched by ".container :first-child" but would not be matched by ".container :first-child-recursive".</div> <div></div> </div> </div>
Received on Thursday, 22 March 2012 18:56:42 UTC