Style Sheets
  Home arrow Style Sheets arrow Page 3 - CSS Constants
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

CSS Constants
By: Chris Heilmann
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-05-09

    Table of Contents:
  • CSS Constants
  • The CSS standard compliant approach
  • Using ID Selectors and Descendent Selectors
  • Moving server side
  • Using Server Side Scripting Languages
  • More examples
  • Parsing CSS with PHP

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

    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.

    More Style Sheets Articles
    More By Chris Heilmann


       · Just a suggestion.Safari seems to struggle with just:header(’Content-type:...
     

    STYLE SHEETS ARTICLES

    - Using the Custom -moz-border-radius Property...
    - Using CSS3`s Border-Radius Property to Build...
    - Adding Semantic Meaning to Styled Code Block...
    - Styling Code blocks with CSS: Using pre HTML...
    - Building Rounded Corners with CSS3
    - Finishing a Casual Navigation Bar with CSS S...
    - Defining a Navigation Bar`s Hover State with...
    - Styling a Blog`s Links Bar with CSS Sprites
    - Creating an Artistic Blog Header with CSS Sp...
    - Defining the Active State of Menu Sections f...
    - Styling the Hover State of a CSS Sprite-Base...
    - Building CSS Sprite-Based Navigation Bars
    - Creating Framed Pictures with CSS
    - Using a CSS Shading Effect to Decorate Images
    - Decorating Images with CSS







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek