spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / diner / ssheets
DHTML Diner Logo

This is a DHTML cross-browser technique. The examples discussed will only work in Navigator 4 and Explorer 4, all platforms.

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Browser-specific Style Sheets (4)

The LINK tag

The LINK tag specifies an external resource related to the HTML page. The relationship of this resource is specified in the REL= attribute. Although the HTML4 specification defines many powerful uses for LINK, presently its most common application is the importing of external style sheets for use in a page. For example, if you have created an external style sheet called myStyles.css, the LINK tag that imports it would be:
<LINK REL="STYLESHEET" TYPE="text/css" HREF="myStyles.css">

Like the STYLE tag, Explorer 4 has provided LINK with the non-HTML4 DISABLED attribute, allowing us to flag it as a non-Explorer style sheet when creating browser-specific styles:

<LINK REL="STYLESHEET" TYPE="text/css" HREF="navigator.css" DISABLED>

The url argument of createStyleSheet()

The createStyleSheet() method, discussed on the previous page, can have a first string argument pointing to an external style sheet:

document.createStyleSheet(stylesheetURL);

We can, therefore, use it to import a complete external Explorer-specific style sheet:

document.createStyleSheet("explorer.css");

Putting it Together

Using a combination of LINK and STYLE, we can create a very elegant method for using browser-specific external style sheets:

<LINK REL="STYLESHEET" TYPE="text/css" HREF="navigator.css" DISABLED>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
    if (document.all) document.createStyleSheet("explorer.css");
//-->
</SCRIPT>

Pros and Cons

Like the previous in-page example, Navigator and Explorer read only the styles meant for them. The style sheets are mutually exclusive, so a third style sheet is necessary for cross-browser styles. We can add this with a regular LINKed style sheet:

<LINK REL="STYLESHEET" TYPE="text/css" HREF="bothbrowsers.css">
<LINK REL="STYLESHEET" TYPE="text/css" HREF="navigator.css" DISABLED>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
    if (document.all) document.createStyleSheet("explorer.css");
//-->
</SCRIPT>


Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

All Rights Reserved. Legal Notices.
Created: Feb 09, 1999
Revised: Feb 09, 1999

URL: http://www.webreference.com/dhtml/diner/ssheets/ssheets4.html