Style Sheets
  Home arrow Style Sheets arrow Page 2 - 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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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 - The CSS standard compliant approach


    (Page 2 of 7 )

    CSS in itself is something like a constant. By defining the styles in classes and IDs or for the elements themselves, we spare ourselves the excruciating work of adding a lot of visual elements and attributes in the markup. In the days before CSS we had to do the following:

    <td valign=”top” align=”right”><font size=”+1”><font color=”blue”>
    <b>Foo</b></font></font></td>

    CSS allows us to define that as:

    td {
    vertical-align:top;
    text-align:right;
    font-size:100%;
    color:blue;
    font-weight:bold;
    } 

    These constant settings are applied to each TD element. Another way:

    td.special {
    vertical-align:top;
    text-align:right;
    font-size:100%;
    color:blue;
    font-weight:bold;
    } 

    The class special is a definition that can be reused for all elements, rather like a constant.

    Using Classes

    CSS classes could be one approach to mimic real CSS constants. Our box example above could be:

    .box {
    background:#ccc;
    border-top:1px solid #eee; 
    border-left:1px solid #eee; 
    border-right:1px solid #aaa; 
    border-bottom:1px solid #aaa;
    padding:.5em;
    margin:.5em 0’;
    }

    We can add this class to any element to apply its definitions. It is also perfectly valid to add several classes, separated by spaces, to one element.

    <h1 class=”box”>
    <div class=”box warning”>

    What we should avoid doing is to name the classes according to how they look, as it can be pretty confusing to see a <div class=”blue bold underline”> that is yellow, of normal weight and without an underline, after a new style guide came along and got applied.

    More Style Sheets Articles
    More By Chris Heilmann


     

    STYLE SHEETS ARTICLES

    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables
    - CSS: Working with Text
    - CSS: Backgrounds
    - CSS for the Newbie







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway