Style Sheets
  Home arrow Style Sheets arrow Page 2 - Working with Multiple Style Sheets
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

Working with Multiple Style Sheets
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-09-11

    Table of Contents:
  • Working with Multiple Style Sheets
  • Working with alternate style sheets
  • Switching alternate style sheets in a cross-browser fashion: defining a basic JavaScript function
  • Swapping alternate style sheets

  • 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


    Working with Multiple Style Sheets - Working with alternate style sheets


    (Page 2 of 4 )

    One of the most common methods used for swapping between different style sheets attached to a given web document involves utilizing alternate style sheets. These sheets are loaded along with the respective web page and theoretically can be selected via a simple menu provided by the user's own browser.

    A simple example of how to use alternate style sheets is shown below:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-
    8859-1" />
    <title>Swapping Style Sheets</title>
    <link rel="stylesheet" type="text/css"href="default.css" />
    <link rel="alternate stylesheet" type="text/css"href="reda.css"
    title="redstyle" />
    <link rel="alternate stylesheet" type="text/css"href="greena.css"
    title="greenstyle" />
    <link rel="alternate stylesheet" type="text/css"href="bluea.css"
    title="bluestyle" />
    <link rel="alternate stylesheet"
    type="text/css"href="fontsizea.css" title="fontstylea" />
    <link rel="alternate stylesheet"
    type="text/css"href="fontsizeb.css" title="fontstyleb" />
    <link rel="alternate stylesheet"
    type="text/css"href="fontsizec.css" title="fontstylec" />
    </head>
    <body>
     
    <h1>Working with multiple style sheets</h1>
     
    <div>
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div>
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div>
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div>
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
    </body>
    </html>

    As you can see, the above (X)HTML file first loads a "default.css" style sheet, which as its name suggests, is used by default, and also includes some alternates by using the "<link> tag and specifying an "alternate style sheet" value for its "rel" attribute as well as a title. Logically, these alternate style sheets can be easily swapped by using the visitor's own menu provided by most modern browsers, like Firefox, for instance.

    However, IE 6 doesn't support this feature. Therefore, switching between alternate style sheets should be performed via client and server-side scripting. In this case, I'll show you how to achieve this style changing process with JavaScript, but naturally you're free to use the approach that best suits your needs.

    So far, you have seen how to attach multiple style sheets to a selected web document. Nonetheless, as you saw earlier, this standard approach isn't supported by IE 6. So, keeping in mind this issue, in the following section I'll define a simple JavaScript function, which will allow users to swap between different alternate style sheets with a few simple links.

    To see how this will be done, please go ahead and read the next few lines. I'll be there, waiting for you.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This first part of the series offers a friendly introduction to swapping between...
     

    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