Banner for Web Design

Back to Lesson 5 Main Page
Lesson 5, Task 3

Making a Cascading Style Sheet

Style information in HTML can be encoded in two ways.  One way is to include the style information within the web page that it affects.  If it's desired to change the appearance of that page later, it's only necessary to change the style code at one location on the page, and the effect is applied to the entire page.

But for web sites that are more than 2-3 pages, it makes more sense to have an external file to which all pages can refer for style information.  If the web site needs to have more than one style, more than one style sheet file can be made.

A Very Brief Overview

A style sheet is a list of default settings.  To understand how to make a style sheet, you need to know about HTML tags.  Review Lesson 5-1 if you need to.  Here is the link to the list of tags from Task 1.  The following table shows the proper syntax for the list

Tag Name Property Value
h1, h2 {color: black;}

In words, "wherever there is a header type 1 or header type 2, make the color of the text black".  On the style sheet, it would look like this:  h1,h2  {color:black; }

Click here to see and example of what a style sheet might look like.  Click here to see what the 'working' style sheet for this course looked like when this page was being made..

NOTE: The files you will be viewing are not real style sheets, but are instead HTML files made to look like a style sheet.  This is done so you can view it in your browser.  A real style sheet has a 'css' extension, and it is just a simple text file.  Most HTML editors recognize the style sheet extension and allow you to edit the style sheet without needing to use a text editor like Notepad.

In the example, you should notice that at some locations the style sheet set a color by using a hex code, but at other locations it sets a color by using a verbal description.  Here is a complete list of the official verbal descriptions for color.  Both Internet Explorer and Netscape support the use of color names, but the W3C standards support only hex numbers for colors.

Spaces in style sheet files (.css) are ignored unless they are within a quotation.  The curly brackets and the semicolons are required.  Some web designers like to space out the lines by putting the brackets on separate lines.  Some think that this practice makes it easier to read the style sheet code.

Using an Online Tutorial for Style Sheets

As with HTML editors, there are ample tutorials on the Internet for making style sheets.  Rather than go into detail here, try one or more of these tutorials, or find another that you prefer:

Linking Your Web Pages to the Style Sheet

Simply making the style sheet is not enough.  You need to let each of your web pages know which style sheet(s) to use, and where they are located.  FrontPage has made this easy.  See how to do it by following this link.

If you are not using FrontPage, your HTML editor may have a way to link to style sheets similar to the way FrontPage does it.  If not, your can always enter the link manually for each page by adding a little code between the <head></head> tags.  Here's what it looks like for the page you are reading now:

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

The '../' tells the web page to look up one step into the directory structure to find the style sheet.  Leave it out if the style sheet is in the same folder as your web page.

Making Your First Style Sheet

Before starting to make your first style sheet, be sure to view a tutorial and have a good understanding of how they work and the proper format.  If your HTML editor has a style sheet maker, you can use it.  Otherwise, use Notepad just like you did when you 'hand coded' your HTML page.

You should already have on your web site three pages that are linked together - practice3-1.htm, practice3-2.htm, and practice3-3.htm.  For this task, you will be creating a style sheet and using it to control the appearance of those three pages.  On your style sheet:

  • Set the attributes for the hyperlinks.  Make the link colors, font sizes, and fonts different from the rest of your pages.  
     
  • Set the background color for the pages. 
     
  • Set the background color for cells in the tables.
     
  • Set at least two other style features that are present on your practice pages.

Save your style as practice.css and put it in the same location in your web as your other practice pages.  Link from each of the three pages back to the style sheet. 

Discussion Board Task 5-3

Make a Discussion Board posting with a link to practice3-1.htm and include your commentary about this assignment.  Paste your style sheet into your Discussion Board posting and explain what you chose for the two (or more) additional style features.

 


OSU Extended Campus  ●  541-737-2676 ●  Fax 541-737-2734
4943 The Valley Library ●  Corvallis, OR 97331-4504
OSU K-12 Online  ●  Services for Students with Disabilities  ● ecampus@oregonstate.edu
Advising Center 800-667-1465 ● Admissions & Registration 541-737-2527

Copyright © 2003, Oregon State University   OSU Disclaimer