SunQuest
 
       Style Sheets
  Home arrow Style Sheets arrow Page 6 - 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  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    CSS Constants - More examples


    (Page 6 of 7 )

    There is no end to the usefulness of this approach. We can reuse cookie data or grab selector names from a database or a parsed document. We could allow an XML notation for the CSS and turn it into valid CSS on the fly.

    An example of how to use parameters sent to the page could be to allow visitors to define a width of the content:

     
    <?php
    header('content-type:text/css');
    header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT"); 
     
    // grab the parameter w and set the variable w to its value
    // if the parameter is not an integer, set w to 740
    $w=740;
    if(isset($_GET['w']))
    {
            $w=preg_match('/(\D)/',$_GET['w'])?$w:$_GET['w'];
    }
    /* Company Colours */ 
    $blue='#369';
    $green='#363';
    $lgreen='#cfc';
    ?>
    #boundary{
            width:<?php echo $w;?>px;
    }
     
    ul#navigation{
            background:<?php echo $blue;?>;
            color:#fff;
    }
    h1{
            border-bottom:1px solid <?php echo $green;?>;
    }

    Or we can apply different color schemes according to the section:

    <?php
    header('content-type:text/css');
    header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT"); 
    $self=$_SERVER['PHP_SELF'];
    /* Colour schemes */ 
    if (preg_match('/aboutus/',$self))
    {
    // About us
            $colour1='#369';
            $colour2='#69c';
            $colour3='#9cf';
    } 
     
    else if (preg_match('/clients/',$self))
    {
    // Clients
            $colour1='#963';
            $colour2='#c96';
            $colour3='#fc9';
    }
    else if (preg_match('/downloads/',$self))
    {
    // Downloads
            $colour1='#693';
            $colour2='#9c6';
            $colour3='#cf9';
    }
    ?>
    ul#navigation{
            background:
    <?php echo $colour1;?>;
            color:#fff;
    }
    h1{
            border-bottom:1px solid 
    <?php echo $colour3;?>;
            color:
    <?php echo $colour2;?>;
    }

    Each of these examples requires the maintainer of the site to know about PHP, and may give her the chance to break it or add unsafe code. If we want to ensure that we have something like CSS constants with a less steep learning curve and less power to the maintainer, we can parse a CSS file with PHP.

    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 6 hosted by Hostway