Re: [css3-selectors] Grouping

On Fri, Jan 8, 2010 at 10:49 PM, Andrew Fedoniouk
<news@terrainformatica.com> wrote:
> Boris Zbarsky wrote:
>>
>> On 1/8/10 12:33 PM, Nikita Popov wrote:
>>>
>>> Which would lead to 3^4 = 81 rules. Hopefully nobody does it.
>>
>> Sure they will.  That's just life.
>>
>> On the other hand, it's not like stylesheets have small numbers of rules
>> as it is.  gmail has several thousand, for example....
>>
>> The biggest danger here, actually, as with any compression scheme, is
>> being a vector for DOS attacks.  And honestly, those are just possible
>> already: you could gzip-compress your stylesheet with lots of redundant
>> rules and it would end up very small to transmit but huge to parse and such.
>>
>
> I have mentioned once already that I've implemented so called style sets (in
> HTMLayout and Sciter).
>
> The set is defined as (same syntax as @media section):
>
> @set somename
> {
>  ... rules ...
> }
>
> and is applied by the style-set CSS attribute.
>
> Using sets original task of reducing these 6 rules:
>
> #authors input, #authors select, #authors textarea,
> #publications input, #publications select, #publications textarea
> {
>  ... rules ...
> }
>
> could be rewritten as:
>
> @set my-section
> {
>  input, select, textarea
>  {
>     ... rules ...
>  }
> }
>
> #authors, #publications
> {
>  style-set: my-section; /* style-set is an inheritable attribute
>                            all elements inside #authors will also use
>                            rules defined in the my-section */
>  ...
> }
>
> This approach has following benefits:
>
> 1) Style rules declared inside the @set are shielded from normal process of
> assigning styles. So they are not creating additional payload.
> Problem "3^4 = 81" simply does not exist in this approach.

I truly don't understand this.  You're still doing precisely the same
amount of matching work.  In this case, you still have to verify that
an element is an input with an #authors ancestor, or an input with a
#publications ancestor, or a select with an #authors ancestor, etc..
Effectively you still have 6 selectors there.  You *cannot* reduce
this amount of work without transforming the document itself.

> 2) Set of style rules is used on all-or-none basis - it is enough
> to redefine:
>  #publications.special
>  {
>    style-set: my-special-section;
>  }
> and the whole set of rules for the sub-tree will be redefined
> as a whole.

It is similarly simple to say

#publications.special :matches(input,select,textarea) {
  //new rules
}

With the same effect.

~TJ

Received on Saturday, 9 January 2010 04:59:58 UTC