- From: Andrew Fedoniouk <news@terrainformatica.com>
- Date: Fri, 08 Jan 2010 20:49:01 -0800
- To: Boris Zbarsky <bzbarsky@MIT.EDU>
- CC: Nikita Popov <privat@ni-po.com>, www-style list <www-style@w3.org>
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. 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. 3) Style sets are solving the problem mentioned by Nikita. Currently style sets are heavily used in so called Master CSS files used by HTMLayout and Sciter to define initial styles of built-in input elements: http://www.terrainformatica.com/wiki/h-smile/built-in-behaviors/master_style_sheet Use of style sets allowed me to have pretty complex system of styles with very low payload. I am pretty sure it can be useful for the generic use too. I have more features around style sets (e.g. one set can be derived from another like: @set std-selector < std-button {} ) but that would be too much, but really convenient as an additional mechanism to straightforward cascading. Especially for complex style systems. -- Andrew Fedoniouk. http://terrainformatica.com
Received on Saturday, 9 January 2010 04:48:37 UTC