CSS based-on styles
December 15th, 2005 by Jerome DahdahJon Meyer proposes a new feature for CSS: based-on, a method to significantly shorten your CSS files by using constants instead of repeating similar declarations over and over again. Basically you can add the “based-on” property to a rule, referencing a previous declaration, and thus inherit the formatting from the linked declaration.
In less technical terms, this means you can define a style that a lot of elements will have in common (such as a 1px border) in ONE rule, and just link to that rule from the other rules. As he mentions himself, this is very similar to Shaun Inman’s Server Side Constants.
I achieve the effect by assigning several classes to an element: one base class such as “messagebox” and then a specific class additionally, such as “success” or “error”. Jon’s method, however, seems more sensible, since it removes the need of adding more than one class to an element. I’d love to see this in CSS3. If this all sounds too confusing and technical, do go read the article, Jon explains it in a more comprehensible way with good examples. Definately worth a read!