Re: Previous-sibling combinator

28.01.2012, 03:34, "Tab Atkins Jr." <jackalmage@gmail.com>:
> 2012/1/27 Marat Tanalin | tanalin.com <mtanalin@yandex.ru>:
>
>> �28.01.2012, 03:08, "Tab Atkins Jr." <jackalmage@gmail.com>:
>>> �On Fri, Jan 27, 2012 at 3:05 PM, Marat Tanalin | tanalin.com
>>> �<mtanalin@yandex.ru> wrote:
>>>> ��Hello.
>>>>
>>>> ��It would be nice to have combinator to select previous sibling.
>>>>
>>>> ��� �P - UL {
>>>> ��� � � �/* Styles for UL element which is
>>>> ��� � � � � previous sibling of P element. */
>>>> ��� �}
>>>>
>>>> ��The "-" combinator is functionally similar to existing "+" combinator, but selects previous-sibling element instead of next-sibling one.
>>>>
>>>> ��So in result we would have "+" to move forward, and "-" to move backward (like element.nextSibling and element.previousSibling in DOM, respectively).
>>> �This is already possible with Selectors 4, using the normal sibling
>>> �combinator and the subject indicator:
>>>
>>> �!ul + p { ... }
>>>
>>> �~TJ
>> �And how would you write following selector using subject indicator?
>>
>> �� �P - UL > LI {...}
>
> Using the future extension to :matches() to allow complex selectors:
>
> :matches(!ul + p) > li {...}
>
> Or, if I get my way, with :has():
>
> ul:has(+p) > li {...}
>
> ~TJ

Looks no so elegant and readable, doesn't it?

Compare:

    P - UL > LI
    :matches(!UL + P) > LI

Probably these features are not mutually exclusive, and we could have previous-sibling combinator in spec _simultaneously_ with all that no-so-readable :matches()/:has() stuff that serves more complex cases.

Received on Friday, 27 January 2012 23:45:40 UTC

OSZAR »