Style Sheets
  Home arrow Style Sheets arrow Page 5 - 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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
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

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

    Table of Contents:
  • Customizing styles: User-Controlled Style Sheets – Part III
  • Breaking the "changeStyle()" function into pieces
  • Listing the complete source code
  • Making the big change: multiple style sheets and persistence
  • Defining the HTML markup and Style Sheets
  • Putting the pieces together

  • 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

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Customizing styles: User-Controlled Style Sheets – Part III - Defining the HTML markup and Style Sheets


    (Page 5 of 6 )

    At this point, it’s necessary to define the markup to be used, in order to explain how the "setStyleSheet()" function is passing the ID corresponding to the style sheet to be activated. The HTML is as follows:

    <h1>Page Name</h1>

    <div id="stylepanel">

    <p>

    <a href="#" title="Change Style" id="switcher1">Style 1</a>

    <a href="#" title="Change Style" id="switcher2">Style 2</a>

    <a href="#" title="Change Style" id="switcher3">Style 3</a>

    <a href="#" title="Change Style" id="switcher4">Style 4</a>

    </p>

    </div>

    <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>

     

    Having listed the HTML markup, things become quite clear. Notice that we’ve assigned style sheets IDs in the sequence "style1", "style2" …"style4". Regarding of the switcher links, their ID's attributes have been similarly assigned in the following way: "switcher1", "switcher2"…"swicther4".

    Each time a link is clicked, it is passing its ID to the "setStyleSheet()" function, which gets the style sheet ID to be activated by simply replacing the "switcher" string with the "style" value. That implies that if the "switcher3" has been clicked, the style sheet for being enabled will be "style3.css." As you can see, the process is a bit tricky, but it works very nicely. Are you sticking with me? Good, because we’re almost finished.

    The rest of our work is to briefly show the CSS rules for the style sheets. Since it’s rather pointless to list the code for each one of them, let’s just define the rules for "default.css." Feel free to specify the rules that you want to apply for the rest of them, making the style change noticeable, when the user selects a different style sheet. So, here’s the code for our default style sheet:

    .content {

         clear: left;

         font: normal 12px "Arial", Helvetica, sans-serif;

         color: #000;

         background: #fff;

         margin-bottom: 10px;

    }

    h1 {

         font: bold 24px "Arial", Helvetica, sans-serif;

         color: #000;

    }

    #switcher1 {

         float: left;

         display: block;

         width: 50px;

         height: 15px;

         padding: 2px;

         border: 1px solid #000;

         font: bold 12px "Arial", Helvetica, sans-serif;

         color: #000;

         text-align: center;

         text-decoration: none;

         background: #ccc;

    }

    #switcher2 {

         float: left;

         display: block;

         width: 50px;

         height: 15px;

         padding: 2px;

         border: 1px solid #000;

         font: bold 12px "Arial", Helvetica, sans-serif;

         color: #000;

         text-align: center;

         text-decoration: none;

         background: #9cf;

    }

    #switcher3 {

         float: left;

         display: block;

         width: 50px;

         height: 15px;

         padding: 2px;

         border: 1px solid #000;

         font: bold 12px "Arial", Helvetica, sans-serif;

         color: #000;

         text-align: center;

         text-decoration: none;

         background: #fc0;

    }

    #switcher4 {

         float: left;

         display: block;

         width: 50px;

         height: 15px;

         padding: 2px;

         border: 1px solid #000;

         font: bold 12px "Arial", Helvetica, sans-serif;

         color: #000;

         text-align: center;

         text-decoration: none;

         background: #393;

    }

    Just let your inspiration soar and define some catching-eye styles for each style sheet!

    Okay, we’ve been playing with sections of code to understand how it’s working. Now, let’s glue the pieces back to see the entire picture. 

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Is adding all the stylesheets as rel="stylesheet". All but one should be...
       · Yes, you're correct about the usage of the "alternate" attribute. Thanks for...
       · We added the changes to the article.
       · Thanks so much for the correction in the article.Best Regards
     

    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