(Site Identification)

'Eye' Focus: Web Support Tutorials

Style Sheets: Imported

Importing an external Style Sheet is similar to linking. The linking method cannot be combined with other methods, but you can combine importing with other methods. It is recommended that you always use a full path or full URL to all style sheet referenced URL's. Though the W3C specifications state that URL's should be relative to the location of the style sheet, some browsers use these paths relative to the document's location.

Here's an example: (skip code)

<html lang="en"><head>
<title>My First Style Sheet</title>
<style type="text/css"><!--
@import url(/.../.../stylsht.css);
h1 {color:orange; font-family:impact;}
--></style>
</head><body>

<h1>Style Sheets</h1>
<p>Customizing your web pages!</p>

</body></html>


This gives:

Style Sheets

Customizing your web pages!


We're using the CSS file, stylsht.css, that we used for the previous example here.

In this example, the browser first imports the main.css rules (the @import line must always be first), then add the embedded rules to it to get the full set of rules for this page.

Notice, however, that H1 has a rule both in the external Style Sheets file and in the embedded styles. What does the browser do in the face of this conflict? The embedded rules win out, and the text displays as orange Impact. As many Style Sheets can be imported as you want. You can then override them with embedded styles as desired.

Caution: Only IE v4.0+ supports Style Sheet importing. Another way to get the same result is to use server side virtual includes. To implement the Style Sheet in this manner the code would look like this: (skip code)

<html lang="en"><head>
<title>My First Style Sheet</title>
<style type="text/css"><!--
<!--#include virtual="stylsht.css"-->
h1 {color:orange; font-family:impact}
--></style>
</head><body>

<h1>Style Sheets</h1>
<p>Customizing your web pages!</p>

</body></html>


An even better method would be to simply load a Linked style sheet first and then define your changes in another Linked or Embeded style sheet.


[Updated: Sunday, November 18, 2007]