One feature designers often wished they had with style sheets are constants –- the chance to define something once and reuse it over and over in the style sheet document. This article shows some techniques for how to achieve that and discusses their pros and cons.
CSS Constants - Using ID Selectors and Descendent Selectors (Page 3 of 7 )
Another option to maintain a certain reusability is to make the settings dependent on an ID on the BODY element. First we define the settings applying to all pages:
border-bottom:1px solid #000;
Then we make the colors dependent on the ID of the body:
border-bottom:1px solid #363;
border:1px solid #363;
border-bottom:1px solid #369;
border:1px solid #369;
The higher specificity ensures that the original settings get overwritten by the “localized” ones.
Depending on which ID we set on the BODY element, the different color settings get applied, without any need to define classes in the HTML.
While this approach means a lot of repetition in the style sheet, it still -– when properly commented –- provides an easy way to brand different pages differently. All we need to do is add one ID to the BODY of the document, which can be done dynamically on the server or via a content management system.
Both solutions are dependent on changes in the markup though, particularly the classes approach. Real CSS constants shouldn’t need that. To make that happen we have to move away from the browser to the server.