CSS can be defined for all web pages in an entire site by
writing the CSS definitions in a plain text file that is referred
to in each of the pages in the site.
Rather than writing the entire CSS definition on each page, as in the previous
example, you can write it to a text file that is only loaded on the first page that a visitor sees at your site.
When the visitor jumps to other pages, the CSS text file will be cached and thus
does not have to be transferred via the internet for subsequent pages.
This means that your pages will load faster while at the same time you will have
the flexibility to change the style for your entire site even after it has been made.
example:
<html>
<head>
<title>my CSS page</title>
<link
rel=stylesheet
href="whatever.css"
type="text/css">
</head>
<body>
<p class="headlines">Welcome</span><br>
<p class="sublines">This is an example of a page using CSS.<br>
The example is really simple, and doesn't even look good, but it shows the technique.
<table border="2">
<tr>
<td class="sublines">
As you can see:<br> The styles even work on tables.
</td></tr></table>
<hr>
<p class="infotext"> example on css applied to a single page.
<hr>
</body>
</html>
|
The above example is the same as the one used
previously for CSS defined for entire pages, with one important exception:
There is no style definition on the page. Instead we added a reference to an external style sheet:
<link rel=stylesheet
href="whatever.css"
type="text/css">
This means that the browser will look for a file called
whatever.css and insert it at the place where the reference was found in the
html document.
To complete our example a file called whatever.css
must exist and it can look like this:
File: whatever.css
.headlines,
.sublines,
infotext {font-face:arial; color:black; background:yellow; font-weight:bold;}
.headlines {font-size:14pt;}
.sublines {font-size:12pt;}
.infotext {font-size: 10pt;}
|
To the <head> of all the site's web
pages we add the line
<link rel=stylesheet
href="whatever.css"
type="text/css">
then the one style definition will be in effect for your entire site.