MSc-IT Study Material
June 2010 Edition

Computer Science Department, University of Cape Town

Imported Style Sheet

This gives you all the advantages of style sheets: by changing a single value in one file the format change is propagated to all of the HTML documents linked to the style sheet. The style sheet is written just as an embedded style sheet is, but, instead of inserting it in an HTML file, it is saved as a separate file (usually with a .css extension). Each HTML document then imports the CSS file. There are two ways to import a file:

Linking it

< link rel="stylesheet" href=" ..//pathname//stylesheet_filename.css" type="text/css" >

Importing it

<style>
@import (http://pathname/stylesheet.css);
</style>
    

The second option will only work for HTML documents on a Web server. If this is not the case, use the first option.

Exercise 4

From the in-line style listing below, create an embedded style sheet and a linked style sheet.

< h1 style="color:red;margin-left:2cm" >h1 heading</h1>
< h2 style="color:red;margin-left:4cm" >h2 sub-heading</h2>
< p style="text-indent:2cm;color:darkred;margin-left:6cm">Paragraph 1</p>
< p style="text-indent:2cm;color:darkred;margin-left:6cm">Paragraph 2</p>
< h2 style="color:red;margin-left:4cm" >h2 sub-heading</h2>
< p style="text-indent:2cm;color:darkred;margin-left:6cm">Paragraph 1</p>
      

You can find a solution to this exercise at the end of this chapter.