- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Thu, 14 Jan 2010 10:40:05 -0600
- To: Alan Gresley <alan@css-class.com>
- Cc: Øyvind Stenhaug <oyvinds@opera.com>, www-style list <www-style@w3.org>
On Thu, Jan 14, 2010 at 10:31 AM, Alan Gresley <alan@css-class.com> wrote: > Structural pseudo-class are different. :first-child and :last-child selects > the first or last element of a given type. With Niels Matthijs proposal this > was for <header> but this could a <p> or a <div>. Unlike the structural > pseudo-classes of :first-child and :last-child which goes across a > particular generation of the DOM, :first-descendant and :last-descendant > would go up or down the tree. Your examples are correct, but your analogy tying :first-child and :first-descendant together are not. "p :first-child" does *not* select the first child of a p element. Well, it does, but not *just* that. Given this code: <p> <span> <i>foo</i> </span> </p> Both the span *and* the i are selected, since they are both first-children who are descendants of p. The :first-child pseudoclass cares only about the DOM, *not* about the selector, and thus does not tie together the matched element and the p in any way - the only link between them is through the descendant combinator. On the other hand, a first-descendant matches *does* care about the selector. "p i:first-descendant" will only match an i if there is no other i between it and the p ancestor. To function, it must know where to start and stop searching for additional i's, and it can only know that by having knowledge about the selector itself. Thus first-descendant is appropriate as a combinator, but not as a pseudoclass, given the way that the lines between them are currently drawn. That's not to say that it must always be this way - it's possible that having a pseudoclass which has knowledge of the selector it's used in would be useful enough to add - but for now I think it best to stick to the categories as they have been established. ~TJ
Received on Thursday, 14 January 2010 16:40:57 UTC