XML technologies / CSS / Advanced websites with CSS / Fixed-width layouts / Zoom layouts / Including alternative stylesheets

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

Many modern browsers, including Firefox and Opera, let users choose between a document’s stylesheets if they are included correctly. To offer multiple stylesheets, uncomment the main stylesheet if you commented it out in the preceding example. Then add this link’s attribute title="default layout". The link to the stylesheet zoom.css receives the attribute title="zoom layout".

<head>
  <title>Footbag Freaks</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" type="text/css" href="fixedwidth.css" title="default layout" />
  <link rel="alternate stylesheet" type="text/css" href="zoom.css" title="zoom layout" />
</head>

In Firefox, which supports alternative stylesheets, choose between the two files by clicking the menu item View > Page Style and selecting a stylesheet. The options shown correspond to the values in the attribute title, as the figure shows.

Selecting different stylesheets in Firefox

Figure: Selecting different stylesheets in Firefox.

What about visitors whose browsers do not offer this choice? Provide your own “style switcher” to offer them multiple stylesheets too. Building these switchers is beyond this book’s scope, but many implementations are possible, using JavaScript or a server-side language such as PHP or ASP. A common JavaScript stylesheet switcher is explained in the article “Alternative Style: Working With Alternate Style Sheets” by Paus Sowden on A List Apart.

  

 

 

 

back to top