How to Refer (Link) to an External Style Sheet
The reference is made in the HEAD section, normally just before
the end </head> tag and follows the following format:
<LINK rel="STYLESHEET" href="path/name-of-file">
Because you are going to save your file my.css into
the same directory that contains your web pages you do
not have to worry about the path portion.
If the file is in a different directory, then you would have
to use either
- One or more ../
- directory(s)
- A combination of the above
Exercise 1. Refer to an External Style Sheet
Step 1. Open your page1.htm file
Using Notepad or your HTML Editor open up your file page1.htm
Step 2. Enter the following code
<LINK rel="STYLESHEET" href="my.css" type="text/css">
on the line before
</head>
Step 2. Save
Its as simple as that. For every file that you wish to use
my.css style sheet you repeat the above, if you have several
files it is easy to copy and paste this line into all your pages.
Step 3. Repeat with your other pages.
Repeat the above with your files Index.html, tut3-exercise.htm
and page3.htm
Writing the Rules
Style Rules are made up from a Selector and Declaration(s)
as follows
Selector {Property 1: value ;Property 2: value ;and so on;}
To make it easier to read, you can write the rules as follows:
Selector {
Property 1: value ;
Property 2: value ;
and so on;
}
- Where Selector is an HTML element such as
H1 or P.
- Where declaration(s) are the properties and
values.
- Properties indicate the aspect of a tags display,
such as background-color:
- and value specifies the actual property such
as red for that property.
- Note the colon : between the property and value.
- If more than 1 declaration (property: value) is required
they are seperated with a semi colon ;
- Declarations are enclosed in curly brackets {
}
This may seem confusing but the example in the next step should
help to make it clear.
Step 1. Enter the Rules
Using Notepad or a Style sheet editor, enter the following.
You can copy and paste this code if you prefer.
Pay particular attention to the puntuation i.e. :
; , - { } make sure they are used in the correct
place. A mistake in the puntuation is hard to spot. Often
H1 {
font-family: Arial, helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
color: red;
text-align: center;
background-color: blue;
}
BODY {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
background-color: yellow;
}
P { font-family: Georgia, "Times New Roman", Times, serif;
font-size: 10px;
color: green;
background-color: white;
}
Step 2. Save as... my.css
Search this site
for a word or phrase.
Place phrases inside "double
quotes"
|
|