As you have seen, web pages have html codes in them that the browser uses to format the page when it is opened. You probably also noticed that the pages are not very pretty. <H1> always gives the same font, size, and colour to the text, regardless of the browser and computer you use. You may have been wondering how to get around that. After all, this page doesn't look like that. The secret is to use a style sheet. You have already seen stylesheets in use for desktop publishing, so why not for web publishing?
There is a default stylesheet for web pages. It is built into the web browser. It is what makes the browser know how to format a regular page - it tells the browser what to do with <H1>, <p>, <br> and other codes.
Custom stylesheets are implemented in web pages using a protocol (agreed on method) called cascading stylesheets. The reason for this name will become apparent as you read through the lesson.
Just like in DTP, style sheets are a way to assign fonts, font sizes, colours, and position to text, relative to the edges of the page. In this case page means the edges of the browser window. So, you can take the HTML style Heading 1 <H1>, for example, and make it Arial, 36 point, green, and positioned 10 points from the left edge. Similarly you can describe how the browser should format any other html text code, including all the headings, paragraphs, text decorations, lists, and text in tables.
They are called cascading stylesheets (CSS for short) because they can be used in three ways, or levels.
In summary, then, they are called cascading stylesheets because there are three levels and inline takes precedence over everything for that line, and internal takes precedence over external for that page. We will look only at external stylesheets.
You've seen that html codes use brackets <> to enclose codes. Cascading stylesheets also use brackets. In this case the { bracket starts the style, and the } bracket ends the style. Stylesheets may be written in detailed version as we do in this lesson, or in an abbreviated - sort of a shorthand - version.
Here is a typical stylesheet. Codes are in red and comments are in green, and are used to explain new items.
.StyleSheetHiddenPlaceHolder { display: none; } <!--- tells older browsers to ignore the stylesheet --->
P { <!--- P for paragraph, { to start the style --->
color : #000000; <!--- sets the colour to black (red is 00, green is 00, and blue is 00)--->
font-family : Arial, Tahoma, Helvetica, sans-serif;
<!--- tells the browser to look on the computer for fonts in this order, and to use the first one it finds. sans-serif will use whatever the computer designates as sans-serif --->
} <!--- ends the style --->
H1 { <!--- heading 1 --->
color : #663300;
font-family : Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size : 200% <!--- twice as big as paragraph text --->
}
H2 {
color : #663300;
font-family : Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size : 160% <!--- 1.6 times as big as paragraph text --->
}
H3 {
color : #663300;
font-family : Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size : 140%
}
H4 {
color : #663300;
font-family : Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size : 115%
}
H5 {
color : #663300;
font-family : Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size : 100%;
}
H6 {
color : #663300;
font-family : Arial, Helvetica, sans-serif;
font-size : 100%;
font-style : italic;
margin-bottom : -0.8em <!--- 8/10 ths of the height of a lowercase x in paragraph text --->
}
BLOCKQUOTE {
margin-left : 5%; <!--- sets the left margin to 5/100 th the width of the browser window. If you resize the window, the spacing will change --->
}A:LINK { <!--- hyperlink --->
color : #6495ED;
text-decoration : none; <!--- turns off underline --->
}A:VISITED { <!--- hyperlink --->
color : #6495ED;
text-decoration : none;
}A:ACTIVE{ <!--- hyperlink --->
color: Maroon; <!--- uses a colour name instead of red, green, blue values --->
text-decoration : none;
}
Stylesheets are used to format text. As you have seen in the sample above, there are a number of text properties. Here is a more detailed list. Note that all settings have a colon : between the setting name and the setting value, and end with a semicolon ;. Codes are shown in red.
Hyperlink formatting codes are a special case. You saw them in the sample stylesheet above. Here is a bit more detail about them
As you know the web is based on hyperlinking. It is the single major feature that makes everything work. The initial standard for hyperlinks was to have them underlined and in blue text. When you clicked on them, they changed colour. Built-in browser stylesheets knew how to format the link. This is called a Standard. Everyone came to recognize this style as a hyperlink.
As you now know, making your own stylesheet allows you to modify the colours, and even turn off underlining of hyperlinks. Of course, if you turn it off, you need to make sure people recognize it as a hyperlink. The code below has the links turned off, Can you identify which code does that?
A:link {
font-family: 'Verdana', 'Arial', 'Comic Sans MS', 'Trebuchet MS', 'Sans-Serif';
text-decoration : none;
font-size: 11pt; color: #0000FF;}
A:visited {
font-family: 'Verdana', 'Arial', 'Comic Sans MS', 'Trebuchet MS', 'Sans-Serif';
text-decoration : none;
font-size: 11pt; color: #990000;}
A:active {
font-family: 'Verdana', 'Arial', 'Comic Sans MS', 'Trebuchet MS', 'Sans-Serif';
text-decoration : none;
font-size: 11pt; color: #FF0000;}
There is another hyperlink property that we have now discussed. It is called Hover. When you mouse passes (or hovers) over the link, this property allows you to cause a visible reaction.
Over time people wanted variety, and since internet users were becoming educated about the web, different ways to implement links could be used and recognized. Hover is one of those different ways. Hover causes the text to change when you move the cursor over it. You don't have to click to get the change in appearance.
When you use hover, you can leave the underline on or turn it off. Generally you apply custom settings to the other parts of the link as well. Here is an example. Remember that text-decoration : none turns off underline. The default browser stylesheet would normally turn underline on. The stylesheet entry for hover looks like this.
A:hover {
font-family: 'Verdana', 'Arial', 'Comic Sans MS', 'Trebuchet MS', 'Sans-Serif';
text-decoration : none;
font-size: 11pt; color: #FF0000;}
Hover is added to the stylesheet, along with the A:link, A:visited, and A:active.
The following samples illustrate a stylesheet in use. Normally you would not use so many colours. They are used to for illustration purposes.
If you use an external stylesheet, you will need to use this line of code. Remember to change the name of the .css file to the name you used.
<link rel="StyleSheet" href="samplestyle.css" type="text/css">
By making a number of different versions of a stylesheet, you can create a variety of layouts for your web pages, and change them just by changing the file.
It is important to note that not all browsers support all features of stylesheets. Netscape and Internet Explorer support different features, and in different ways, so it does not always look the same in both. The stylesheet that is used in this course is designed primarily for Internet Explorer.
This has been an introductory look at style sheets. Stylesheets can be much more sophisticated and specify a very large array of settings for web pages. If you are interested in learning more about stylesheets, try a few of these sites.
The purpose of this activity is to develop capability with using stylesheets
This activity will be done using Notepad. You will need to save the following files into the same folder. If they are in different folders, the link for the stylesheet will need to be changed.
Complete the following. You will be making a series of changes to the web page and to the stylesheet, so you need to save your files after each change.
There is no self test for this lesson.