Style Sheets
  Home arrow Style Sheets arrow Page 3 - Customizing styles: User-Controlled Style ...
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

Customizing styles: User-Controlled Style Sheets - Part II
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2005-04-13

    Table of Contents:
  • Customizing styles: User-Controlled Style Sheets - Part II
  • Changing entire style sheets: the first basic approach
  • Listing full source code
  • Summary and further reading

  • 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


    Customizing styles: User-Controlled Style Sheets - Part II - Listing full source code


    (Page 3 of 4 )

    As I promised before, if you wish to implement this initial approach in your Web application and add your own improvements, here's the full code for changing style sheets:

    <html>

    <head>

    <title>CHANGING STYLES BY STYLE SHEET</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <link rel="stylesheet" type="text/css" href="default.css" id="default" />

    <link rel="stylesheet" type="text/css" href="accessible.css" id="accessible" />

    <script language="javascript">

    // disable accessible style sheet

    var accessibleSheet=document.getElementById('accessible');

    accessibleSheet.disabled=true;

    changeStyle=function(){

         var switcher=document.getElementById('switcher');

         switcher.onclick=function(){

               var defaultSheet=document.getElementById('default');

               if(!defaultSheet){return;}

               // disable default style sheet

               defaultSheet.disabled=true;

               var newSheet=document.getElementById('accessible');

               if(!newSheet){return;}

               // enable accessible style sheet

               newSheet.disabled=false;

               return false;

         }

    }

    // execute function when page is loaded

    window.onload=function(){

         if(document.getElementById){

               changeStyle();

         }

    }

    </script>

    </head>

    <body>

    <h1>Page Name</h1>

    <p><a href="#" title="Change Style" id="switcher">Change style</a></p>

    <div class="content">

    <p>Content for div1 goes here...Content for div1 goes here...Content for div1 goes here...</p>

    </div>

    <div class="content">

    <p>Content for div2 goes here...Content for div2 goes here...Content for div2 goes here...</p>

    </div>

    <div class="content">

    <p>Content for div3 goes here...Content for div3 goes here...Content for div3 goes here...</p>

    </div>

    </body>

    </html>

    Taking a look at the full source code, it's becomes clear that once both style sheets have been defined, the first two lines of JavaScript code deactivate the "accessible" style sheet, making "default.css" the unique active style sheet in the document.

    Then, with a single style sheet to deal with, the "changeStyle()" function is executed after the document has been loaded. Finally, when the user clicks on the switcher link, style sheets are changed gracefully.

    From the previous lines, it's easy to deduce that specifying different rules for the same "content" CSS class applied to the <div> elements, and defined in both style sheets, can achieve a dramatic style change with minimum of effort. With a little bit of JavaScript code, we're switching style sheets on and off. Definitely, we have improved our background about style changes.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Over this second article, the process to change styles in web documents is taken one...
       · I took the liberty and clean the example up and make it more...
       · Hi Chris,Definitively that was a good addition to the existing changeStyle()...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







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