W3C home > Mailing lists > Public > www-style@w3.org > January 2015

Re: Previous-sibling combinator

From: Marat Tanalin <mtanalin@yandex.ru>
Date: Thu, 22 Jan 2015 03:32:52 +0300
To: Tab Atkins Jr. <jackalmage@gmail.com>
Cc: "www-style@w3.org" <www-style@w3.org>
Message-Id: <4043301421886772@web9m.yandex.ru>
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:
>>>> šš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 { ... }
>>>
>> š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 {...}

Given that the subject indicator is dropped [1], and `:has()` is not going to be available in fast profile (and therefore in CSS) [2], it probably makes sense to reconsider adding the previous-sibling combinator available in CSS.


[1] https://lists.w3.org/Archives/Public/www-style/2014Feb/0617.html
[2] http://dev.w3.org/csswg/selectors/#fast-profile
Received on Thursday, 22 January 2015 00:33:23 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:50 UTC