Style Sheets
  Home arrow Style Sheets arrow Page 3 - Using Persistent Styles with Multiple Styl...
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 
VeriSign Whitepapers 
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

Using Persistent Styles with Multiple Style Sheets
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-09-12

    Table of Contents:
  • Using Persistent Styles with Multiple Style Sheets
  • Refreshing some previous concepts and methodologies
  • Working with persistent style sheets
  • Defining some basic JavaScript functions
  • Listing the full source code of the style switching application

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

    Using Persistent Styles with Multiple Style Sheets - Working with persistent style sheets


    (Page 3 of 5 )

    As I explained in the previous section, I'm going to demonstrate how to swap several persistent style sheets attached to a specific web document by using a straightforward approach that is similar to the one used for working with alternate style sheets.

    In case you don't know what persistent style sheets are, then let me describe in a few words their core functionality. Basically, persistent style sheets are loaded by default by a given web page and generally are used to define the resetting styles for the web page in question and its basic appearance as well. Also, they can be included into a concrete web document by specifying a value of "stylesheet" for the "rel" attribute of <link> tags, and don't require the inclusion of a "title" attribute.

    As you can see, using persistent style sheets is indeed an understandable process, but certainly one of the most interesting aspects of working with them rests upon the ability to combine different styles in one web page.

    To demonstrate this concept, below I listed the definition of a simple (X)HTML file, which loads in the beginning seven persistent style sheets which provide the different DIVs and paragraphs included in the file with some basic visual styles. However, as you'll see later, these styles can be easily combined by activating/deactivating a few CSS classes included in the respective style sheets.

    Now, having said that, have a look at the signature of the following web document, which as I stated before, loads a few persistent style sheets: 

    <!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>Multiple style sheets</title>
    <link rel="stylesheet" type="text/css" href="default.css" />
    <link rel="stylesheet" type="text/css" href="red.css" />
    <link rel="stylesheet" type="text/css" href="green.css" />
    <link rel="stylesheet" type="text/css" href="blue.css" />
    <link rel="stylesheet" type="text/css" href="fontsize1.css" />
    <link rel="stylesheet" type="text/css" href="fontsize2.css" />
    <link rel="stylesheet" type="text/css" href="fontsize3.css" />
    </head>
    <body>
      <h1>Working with multiple style sheets</h1>
     
    <div class="container">
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div class="container">
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div class="container">
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
     
    <div class="container">
       
    <p>This is the sample content of the DIV.</p>
     
    </div>
    </body>
    </html>

    As you can see, the previous (X)HTML file includes seven persistent style sheets in the beginning. So far, this process is very easy to follow, right? To clarify further how the "default" style sheets are loaded at first by the previous web document, below I included a screen shot that demonstrates clearly this process:

    Now that you have seen how the DIVs and paragraphs included in the previous web page are basically styled by the corresponding "default.css" file, it's a good time to jump forward and see how to combine the styles declared by this file with the ones specified by the other sheets.

    As you might have guessed, this combination of styles will be performed via the interaction of three simple JavaScript functions, whose respective signatures will be shown in the section to come, so click on the link below and keep reading.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This second article of the series introduces you to the use of multiple persistent...
     

    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


    Iron Speed





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