Re: Proposal: inheritance of styles -in the stylesheet itself-

[Mon, 21 Oct 2002 02:09:19 -0400] Doug Schepers:
>Brent Boyer wrote:
>>
>> What I propose for CSS is that it allow inheritance of styles -on the
>> stylesheet itself-.
[...]
>> 	.normalText {
[...]
>> 	}
>>
>> 	.large1Text extends normalText {
>> 		font-size: 1.2em;
>> 	}
[...]
>I think a more flexible mechanism, with a more CSS syntax, would be
>something like:
[...]
>	.large2Text {
>		@inherit: .normalFont !important;
>		@inherit: .normalText;
>		font-size: 1.44em;
>	}
>
>... where ".large1Text", ".large2Text" have all the properties of
>".normalFont" and ".normalText", with the exception that ".large2Text" would
>take the "important" value of blue for "color," rather than inheriting.
>
>But, like I said, the basic idea seems sound, regardless of the syntax.


I'm not so sure it is.  Class selectors in CSS are just abbreviations
for attribute selectors; e.g.:,
     x.y
means:
     x[class~=y]
(when the document language is HTML) and nothing more.  (See:
     http://www.w3.org/TR/REC-CSS2/selector.html#class-html
for the definition of a class selector.)  Note that class selectors
(the "dot notation" that is, not the attribute selector form) are
valid only when HTML is the document language.

So to say class2 "inherits from" class1 would be equivalent to constructing
a rule that says something like, "Whenever a selector including
'[class~=class2]' matches an element, treat that element as if
'[class~=class1]' also matched"... except then there's the question of
precedence.


Suppose we have:

     .article {font: bold small Arial;}
     .sidebar {inherit: .article; font-weight: normal; color: blue;}
     .article {color: black;}

Now, is:

     <P CLASS="sidebar">

blue (because "black" comes from inheritance) or black (because that rule
appears later in the style sheet)?  If you think the former --- how is:

     <P CLASS="sidebar article">

treated?

And how do we analyze:

     .article      {color: black;}
     DIV.article   {color: green;}
     DIV.article P {color: red;}
     .sidebar      {inherit: .article;}
     P.sidebar     {color: blue;}

when:

     <DIV CLASS="sidebar"><P>paragraph1</P></DIV>
     <DIV CLASS="sidebar"><P CLASS="sidebar">paragraph2</P></DIV>

appears in the document?  What color is each paragraph?


All in all, I think that while the idea sounds nice at first, it's
inconsistent with the "logical model" of CSS, and would open up
a host of ambiguous cases that would have no obvious resolution.
-- 
Randall Joseph Fellmy aka Randy@Coises.com

Received on Monday, 21 October 2002 19:38:52 UTC