Re: [css3] Suggestion: Selector variables or "synonyms"

On Feb 8, 2008, at 1:19 AM, Mike Wilson wrote:

> Adding the possibility to let one rule inherit the
> property assignments from another rule (or actually
> declaration set) could look something like this:
>
>   .mycolorandfont {
>     color: #444;
>     font-size: 77%;
>   }
>   input[type="radio"] {
>     INHERIT_DECLS(.mycolorandfont);
>     /*other settings for radio*/
>   }
>   input[type="checkbox"] {
>     INHERIT_DECLS(.mycolorandfont);
>     /*other settings for radio*/
>   }
>
> Note that I am not suggesting any particular syntax here,
> it could be using normal classes like above, some new @-
> rules, or maybe something completely different based on
> object-oriented keywords.
>
> Best regards
> Mike Wilson


That would certainly be useful. I think one of the objections in the  
past was that this would make the cascade more complicated, and might  
even lead to circular logic, if say A inherited B, B inherited C, and  
C inherited A. But this would be a good idea for some sort of  
constants, which I would imagine being declared before most other  
rules, to avoid that problem. Such as the following syntax, where a  
constant definition is not allowed to contain other constants (except  
perhaps those that had been defined above it):

/* for groups of property/value pairs that are used in multiple  
places: */
@constant mycolorandfont { color: #444;  font-size: 77%;  border- 
color;blue; }
/* for long sequences of selectors that are used in multiple places: */
@constant navlink( #sidenav ul li a, #topnav ul li a )

input[type="radio"] {
	constant:mycolorandfont;
	line-height:90%;
	 /*other settings for radio*/
}
  input[type="checkbox"] {
	constant:mycolorandfont;
	line-height:110%;
	 /*other settings for checkbox*/
}
navlink:link, navlink:visited { color:black; background-color:yellow; }
navlink:hover { background-color:black; color:yellow; }
navlink:active { background-color:black; color:red; }

So, in this syntax, "@constant' means you are defining the constant.  
For the groups of property values, they are assigned within whichever  
rule you choose, via the "constant" property. For selectors, after  
they are defined, they are used as though they are just simple  
selectors.

This probably wouldn't help with Jens' first use case (selector  
changes that catch old versions of HTML pages), but would be an  
elegant and fairly simple way to implement his second (shortened  
versions of long contextual selectors). It would be a good way, IMHO,  
of implementing Mike Wilson's and Daniel Glazman's general idea  
(grouping sequences of properties into shortened forms, and allowing  
the author to make wide-scale multi-rule changes by changing a single  
rule), without getting into problems associated with multiple (and  
possibly circular) inheritances and cascade.

Received on Friday, 8 February 2008 16:21:04 UTC