Cascading Style Sheets - Understanding When & How to Use Them.

Purpose: Students will understand how and when to use Cascading Style Sheets (CSS).

Explanation of Cascading Style Sheets (CSS)

View an HTML Page With No Tags - Then View the Same Site With Tags - Finally View the Same Site With Css.


Project #1: My First Website Using CSS!

  1. Find the "My First Website: Geography / San Francisco" that you created.
  2. Create a duplicate (copy and paste it.).
  3. In the Documents folder, create and add a "Styles.css" page (on PC use Notepad).
  4. Edit this website so that it does not rely on Tags for its formatting, but relies on css.

Using Cascading Style Sheets
There are three methods for applying Styles to a web page:

  1. Internal Style Sheets (Used with small sites.)
  2. External Style Sheets (Used with any sites. Very common.)
  3. Inline Styles (Used to change just one line of code - rarely used. Usually used to over ride an External Style Sheet.)

Internal Style Sheets
Internal Style Sheets allow you to format text by writing a Style Declaration only once…not each and every time you write a heading or a paragraph. You declare the Style in the Header of the page.  Any time it appear in the body, it automatically receives the attributes declared in the Header.

Project #2: Creating An Internal Style Sheet Using CSS!


External Style Sheets
With an external style sheet, you create a web page in which you will write all the Styles that you want to appear on your web pages. All you have to do is add a link to it in the <head> section of the HTML page.The benefit is that you can reuse this external Cascading Style Sheet over and over on future websites and you can change the look of an entire web site by changing one style in this file.

Project #3: Creating a Website Using an External Style Sheet!


Inline Styling
Inline Styling is different. Inline Styling is written directly in the line of code, just like you did with Tags. So why use Inline Styling? You would use it when you want to apply a unique style to a section of text. This web site would most likely already be using an external style sheet. Eg. You were writing an essay and you wanted the title on your school's website to appear in specific colors and bold. The inline style would supersede the sites external style sheet.
Note: Inline Styles should be used sparingly, because they defeat the purpose of separating the style from the content.

In this example, I created one web page with an External Style Sheet. The title on the page is "St. Helena H.S. Environmental Club." The Style Sheet makes all "Titles" Red. On this specific page, I want it to be Green. Notice that I did not edit he code on the External Style Sheet because I wanted red to remain the color on all the other pages. I wrote an Inline Style, or in other words a "Tag", directly onto the page - it superceded the External Style Sheet.

Project #4: Editing a Page Using an Inline Style!