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

Re: proposal for a new css combinator

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Fri, 15 Jan 2010 19:08:31 -0800
Message-ID: <4B512DAF.9000203@terrainformatica.com>
To: Lachlan Hunt <lachlan.hunt@lachy.id.au>
CC: Niels Matthijs <niels.matthijs@internetarchitects.be>, www-style list <www-style@w3.org>
Lachlan Hunt wrote:
> Niels Matthijs wrote:
>> I'm quite sure that someone before me must've thought about this,  or
>> maybe I just didn't look closely enough at the latest specs, but I
>> believe we are missing an important css combinator.
>> For the full explanation you can check the following article:
>> http://www.onderhond.com/blog/work/missing-css-combinator
>> In short, I'd like something between the space and child combinator. A
>> combinator that allows for an (x) number of levels between parent and
>> child, but stops at the first matching level it hits.
> Here's a similar proposal of mine from 2003.  It's basically the same 
> idea, but using ^ instead of %.
> http://lists.w3.org/Archives/Public/www-style/2003Dec/0034.html

Here is one more practical use case for such selector.

Let's say we have following markup:

<body dir="rtl">
   <div dir="ltr">

There is a need to have selector that will allow to specify following:

<if ltr environment>  ul
   padding-left: 10px;
<if rtl environment>  ul
   padding-right: 10px;

<if ltr environment> is simply this: "nearest parent of the element with 
defined @dir and this @dir is precisely 'ltr'".
And <if rtl environment> is this: "nearest parent of the element with 
defined @dir and this @dir is precisely 'rtl'".

Seems like that proposed '%' (or '^') will not allow to do that - is not
generic enough.

I think that instead of '%' we should have something like "no such 
parent" construction.

So to select nearest <header> to the .box  we can write:

.box no(header) header { ... }

And for the ltr/rtl environment testing we can write simply this:

[dir=ltr] no([dir]) ul { ... ltr styles ... }
[dir=rtl] no([dir]) ul { ... rtl styles ... }

So such no() combinator:

A no(B) C

is pronounced as:

If there are any parent elements in the child/parent chain between C and 
A then none of these parent elements should match B.

Such selector can be implemented pretty effectively - it has 
computational complexity of "A B C" selector.


Andrew Fedoniouk.

Received on Saturday, 16 January 2010 03:08:54 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:07:42 UTC