| Using ID Selectors and Descendent Selectors |
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:
font-family:Arial,Sans-Serif;
border-bottom:1px solid #000;
Then we make the colors dependent on the ID of the body:
border-bottom:1px solid #363;
border-bottom: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. |
| Return to Listing |