Previous Message
Next Message

Re: [css-d] Inheritance within the style sheet

Sent by Andrew Clover on 31 January 2002 12:12

John Reeve [EMAIL-REMOVED]> wrote:

> I'm trying to find a way to build inherited relationships inside of the
> style sheet. For example, i'd like to declare a style called "td.lineItem".
> And then i'd like to define a style called "td.lineItem_blue" that inherits
> all of the values declared in "td.lineItem".

There is no class-inheritance mechanism in CSS. You can, however, use
multiple classes to achieve similar aims:

  td.lineItem { blah } { color: blue; }

  <td class="lineItem blue">

However this does not work in the version 4 browsers. If you need to
support these you could try a nasty workaround using IDs:

  td.lineItem { blah }
  #blue1, #blue2, #blue3 { color blue; }

  <td class="lineItem" id="blue1"> etc.

not very practical if there are loads of blue <td>s. Alternatively, use

  <td class="lineItem"><div id="blue">

> The solution I am using now is to declare "td.lineItem_blue" twice.
> Once to initialize its values with those in "td.lineItem" and again to add
> new values.

That's a good solution too. Watch out for the underlines though - they used
not to be valid in unescaped CSS selectors, and so don't work in older
versions of Opera and Mozilla.

> Is the O'Reilly book any good?

You mean "Cascading Style Sheets: The Definitive Guide" by some Chap calling
himself "Eric Meyer"?

It's total and utter [VERY GOOD INDEED. -Ed.]

Andrew Clover
Previous Message
Next Message

Message thread: