Re: proposal for a new css combinator

On Thu, Jan 14, 2010 at 6:41 AM, Alan Gresley <alan@css-class.com> wrote:
> So you are saying that you want to match the first descendant of a
> particular element in the DOM. This could be done like first-child and would
> be a structural pseudo-class.

Yeah, that's what's desired, but note that multiple elements can match
here.  For example, in the following code:

<article>
  <section>
    <h1>foo</h1>
    <p>bar bar bar</p>
    <section>baz</section>
  </section>
  <div class=special>
    <section>qux</section>
  </div>
</article>

A selector like "article % section" should match both the first child
of article, and the section inside of the div.  It wouldn't match the
section containing "baz", though, since that has another section
ancestor between it and its closest article ancestor.

> .focusBlock header:first-descendant {
> // style rules //
> }
>
>
> In theory you could also have last-descendant.
>
>
> .focusBlock header:last-descendant {
> // style rules //
> }

:last-descendant would actually be marginally easier to implement, if
I'm thinking correctly, and plenty useful on its own (for many of the
same reasons that jQuery's closest() method is so useful).

~TJ

Received on Thursday, 14 January 2010 13:52:12 UTC