Re: [css3-selectors] Grouping

On Fri, Jan 8, 2010 at 7:55 AM, Nikita Popov <privat@ni-po.com> wrote:
> Often several elements on a page have similar style. So you want to group
> them in one rule.
> The only possibility to do this, is the ",". The disadvantage is, that you
> often need to repeat large parts of the rule, but only small parts change.
>
> An Example: My body-Elements gets a class, containing the actual page, e.g.
> class="add". Now I want to give all input, textarea and select elements on
> this page, that are in two different divs some styling:
>
> .add #authors input, .add #authors select, .add #authors textarea,
> .add #publications input, .add #publications select, .add #publications
> textarea
> {
> ...
> }
>
> Not very nice.
> It would be much more convenient to group parts, that aren't changing:
> .add
> (#authors input, #authors select, #authors textarea,
> #publications input, #publications select, #publications textarea)
> {
> ...
> }
>
> Or even
> .add (#authors, #publications) (input, select, textarea)
> {
> ...
> }
>
> The code gets shorter and more readable.

I've asked for this before, under the :any() pseudoclass.  It works
just as you have it - that last rule would be written as ".add
:any(#authors,#publications) :any(input,select,textarea)".  It's
really a necessity for many cases where you end up with a
combinatorial explosion of selectors - this one selector replaces six
nearly identical ones.

Implementors have agreed that it's basically just syntax sugar, and
wouldn't require any special mechanics or cause performance
regressions.  It's just not in a draft yet, is all.

~TJ

Received on Friday, 8 January 2010 15:19:46 UTC