Note: There are no new demos added at this point and this site is in maintenance mode
start svg demo download
cr5.0 o10.6 ff3.6 sa5.0

Alternate Stylesheets

author: Vincent Hardy posted: August 14, 2010 at 06:00 PM categories: style view comments

Running the demo

Click on the "Start SVG Demo" at the top of this page. Then, in the demo page, select the name of the alternate stylesheet to apply

Click on the 'start svg demo' button on this page. Then select one of the links next to the 'select stylesheet' prompt to to enable the desired stylesheet (and disable the others).

Applying CSS styles to SVG and HTML from one stylesheet

SVG is fully stylable with CSS and features like alternate stylesheets apply. This demo shows a web page with both HTML and SVG content. At the top of the page, the user can select one of the available stylesheets which gets enabled while the others are disabled. This mechanisme is generally useful to allow users to select a prefered style, for example chosing high contrast if needed for accessibility reason.

The demo shows how the style of SVG graphical element is subject to CSS styles, just like any other HTML element is and that the same stylesheet can naturally be used to style both SVG and HTML content.

The key to turning stylesheets on or off is to change the disabled property on the <link> element referencing the stylesheets like so:

var link = ...; // e.g., from document.getElementsByTagName("link");
link.disabled = false; // Enables the stylesheet
....
link.disabled = true; // Disables the stylesheet

The code for turning stylesheets on and off was inspired by the example found at A list appart.

blog comments powered by Disqus