Re: Selecting the parent of an element

On 10/06/2011 01:53 AM, Barry van Oudtshoorn wrote:
> Hi all.
>
> Masata Yakura recently posted an update on Google+ [1], which alluded to the ability to select parents of elements within a
> CSS selector [2]. This has been picked up elsewhere on the web; for example, on David Walsh's site. [3]
>
> In essence (as I understand it), this allows you to specify the element to which the styles should be applied by prefixing it
> with a '$' symbol; $E > F matches an E element which is a parent of an F element (incidentally, there's a typo in the table
> for [2] for this example).
>
> Whilst I certainly welcome this idea, I believe that there are some issues with it, and I would like to propose an alternative
> syntax. I've outlined some of these problems, and the proposal, below.
>
>
> *Problems*
>
> 1. This breaks the natural reading order of CSS selectors: the right-most "part" of a selector no longer identifies the
> element to which the rules should be applied.

Your reversed-combinator suggestion has the problem that the selector chain no longer proceeds forwards through the element tree.
I personally find that more disorienting.

> 2. It provides a very specific solution to a very specific problem, rather than a generic, extensible solution. Using this
> syntax, how would one, for example, identify a preceding direct sibling of an element E?

$* + E

It has the same structure as * + E, except instead of the E you pick the * as the subject.

> 3. The '$' symbol is already in use -- E[foo$="bar"] matches an E element whose "foo" attributes ends with "bar". This is
> clearly a nod to regular expression syntax.

The question of what symbol to use is still open; someone suggested ? so the latest
editor's draft is using that since there were objections to $.

~fantasai

Received on Thursday, 6 October 2011 22:58:36 UTC