Re: Previous-sibling combinator

17.08.2012, 08:54, "Greg Houston" <gregory.houston@gmail.com>:
> I think the exclamation point was put in the wrong place. It would be
> better to simply reverse a directional selector. Not only is it much
> easier to write but it makes a little more sense where we generally
> think of the exclamation point as meaning "not", like != (not equal).
> Not UL doesn't make binary sense, but !+ (not next) makes a bit more
> sense for previous.
>
> :matches(!UL + P) > LI
> vs.
> P !+ UL > LI
>
> :matches(!UL ~ P) > LI
> vs.
> P !~ UL > LI
>
> :matches(!UL > P) > LI
> vs.
> P !> UL > LI
>
> :matches(!UL P) > LI
> vs.
> P ! UL > LI
>
> Not sure If I am writing this one correctly using nested :matches...
> :matches(!panel > :matches(!header > :matches(!.float-right > .btn))) > footer
> vs.
> .btn !> .float-right !> header !> .panel > footer

This is an interesting alternative syntax. Since it's combinator too (as `-` is), it has similar benefits over horrible `:matches()`. Additionally, it makes syntax of combinators somewhat more universal as for ability to reverse their meaning (next / previous sibling, child / parent element).

It makes sense to take into account though, that in case of ancestor (reversed context) combinator (`P ! UL`), it would anyway require spaces around combinator to make it unambiguously different from subject indicator (similar to how spaces are required around `-` to make it different from dashes inside identifiers and names of pseudoclasses).

Also, I would prefer to use `<` character as direct parent combinator:

    UL < DIV {}

It looks more intuitive than:

    UL !> DIV {}

So, in summary, we could use:

    * ` - ` as previous-sibling combinator (as proposed by me),
    * `<`   as direct-parent combinator,
    * `!~`  as previous general-sibling combinator,
    * ` ! ` as ancestor combinator.

`<`/`>` and `+`/`-` are used to be opposite, so it make sense to use them together. At the same time, there is no unambiguously opposite things for `~` and for space character, so it's ok to use `!~` and ` ! ` in these (and only these) two cases.

Received on Friday, 17 August 2012 15:55:42 UTC