[css-selectors] descentant up to a certain depth

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[css-selectors] descentant up to a certain depth

Hr Gwea
Is there any plans or ideas to simplify selectors like this:

elem1 > elem2,
elem1 > * > elem2,
elem1 > * > * > elem2 {...properties...}

i.e. all elem2 that are children, grandchildren or great-grandchildren of elem1.
More generally, a descendant combinator that let us specify the max depth of the descendants.

If not, can I propose a solution?

Reply | Threaded
Open this post in threaded view
|

Re: [css-selectors] descentant up to a certain depth

Brad Kemper

> On Jul 2, 2016, at 7:51 PM, Hr Gwea <[hidden email]> wrote:
>
> Is there any plans or ideas to simplify selectors like this:
>
> elem1 > elem2,
> elem1 > * > elem2,
> elem1 > * > * > elem2 {...properties...}
>
> i.e. all elem2 that are children, grandchildren or great-grandchildren of elem1.
> More generally, a descendant combinator that let us specify the max depth of the descendants

In selectors 4, :not() can take a selector list.

elem1 elem2:not(elem1 * * * elem2) {
  /* should do what you want */
}

> If not, can I propose a solution?

You can always propose.
Reply | Threaded
Open this post in threaded view
|

Re: [css-selectors] descentant up to a certain depth

Hr Gwea
Ok, that reduces the duplication a bit, but still requires elem1 and elem2 to be named explicitly twice. Which is not convenient when elem1 and elem2 are complex selectors.

I was thinking of the possibility to pass parameters to the descendant combinator.
For example:

elem1 >(3)> elem2  /*descendants up to third level*/
elem1 >(2,5)> elem2  /*descendants from second to fifth level*/
elem1 >(1)> elem2  /*same as child combinator*/

How do you like it?



On Sun, Jul 3, 2016 at 12:03 PM, Brad Kemper <[hidden email]> wrote:

> On Jul 2, 2016, at 7:51 PM, Hr Gwea <[hidden email]> wrote:
>
> Is there any plans or ideas to simplify selectors like this:
>
> elem1 > elem2,
> elem1 > * > elem2,
> elem1 > * > * > elem2 {...properties...}
>
> i.e. all elem2 that are children, grandchildren or great-grandchildren of elem1.
> More generally, a descendant combinator that let us specify the max depth of the descendants

In selectors 4, :not() can take a selector list.

elem1 elem2:not(elem1 * * * elem2) {
  /* should do what you want */
}

> If not, can I propose a solution?

You can always propose.