Website Design Edmonton       Website Design Feedback       Website Design Sitemap     Contact Website Design Company
Website Designers R Us - Home
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:

body{
        font-family:Arial,Sans-Serif;
        background:#fff;
        color:#333;
}
#nav{
        width:10em;
        margin:0;
        padding:.5em;
}
#nav li{
        list-style-type:none;
}
h1{
        font-size:120%; 
        border-bottom:1px solid #000;         
}

Then we make the colors dependent on the ID of the body:

#home h1{
        border-bottom:1px solid #363;  
        background:#cfc;       
}
#home #nav{
        border:1px solid #363; 
        background:#cfc;       
}
#contact h1{
        border-bottom:1px solid #369;  
        background:#ccf;       
}
#contact #nav{
        border:1px solid #369; 
        background:#ccf;       
}

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

Website Designers R Us is a professional Internet strategy and Web design company based in Toronto, Canada. We specialize in best-in-class website design, online marketing, Flash multimedia, corporate identity and print graphics. Website Designers R Us features an integrated team of web consultants, creative designers, writers, programmers and marketing professionals that know how to get online results
 Home          ::             About Us          ::             Support            ::             Services            ::             Link Partners          ::             Contact

Copyright © 2006-2011 Website Designers R Us, a DOT Specialist Company. All rights reserved.