| home / experts / dhtml / diner / ssheets |
![]()
This is a DHTML cross-browser technique. The examples discussed will only work in Navigator 4 and Explorer 4, all platforms. |
Browser-specific Style Sheets (4)The LINK tagThe 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 TogetherUsing 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 ConsLike 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
All Rights Reserved. Legal Notices.
Created: Feb 09, 1999
Revised: Feb 09, 1999
URL: http://www.webreference.com/dhtml/diner/ssheets/ssheets4.html