3.1  Style Sheets 

Index Code Tester

OBJECTIVE

DISCUSSION

Style Overview

How to Add Style

<div style = "font-family: courier">

<head>

<style>

H1 {

font-style: italic;
font-weight: bold;

}

.myClass {   /* comment ... defines a class */

font-weight: 200;
font-size: 36pt;

}

#myID {    /*defines format for an id */

color: red;
font-size: 50px;

}

</style>

</head>

<body>

<div class = "myclass">abc</div>

<div id = "myID">def</div>

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


Other Notes

EXERCISES

1.  Explain the three different methods for adding style.

2.  What is the format for defining a class?

3.  Create a simple HTML page and save as e3_2_3.htm.  Add a <div> section in the <body> and add some text in this <div> section. Also add some text that is not in the <div> section.

a.  Create a style file called mystyle.css.  In this .css file add style properties for the body to set its font-family to "arial" and its background-color to "yellow".  Open and test your e3_2_3.htm page in the browser.  Make sure that the font is arial and the page color is yellow.

b.  Now add a definition for a class called mydiv in the style file.  In this mydiv class define the properties for font-family and font-size.  Set the font-family propery to courier and the font size to 36pt. 

c.  In the <div> tag in e3_2_3.htm, sets its class to "mydiv".  Open your page in the browser.  What is the font of the text inside the <div> tag?  What is the font outside the <div> tag? 

d.  In your e3_2_3.htm file add an internal style section.  Create a class in this section called mydiv.  In this mydiv class define the properties for font-size and background-color.  Set the font-size to "smaller" and the background-color to "red".  Test your page.  What is the font-size of text in the <div>?  What is the color?  Which definition of the mydiv class takes precedance?

e.  In your e3_2_3.htm file add an inline style property in the <div> tag to change the background-color of the <div> to blue.  View your page again.

4.  Based on the results in #3, explain what is meant by Cascading Style Sheets.

5.  Create a style sheet and define styles for (1) <body> tags,(2) a class called "boldRed", and (3) an ID called "lightYellow".  The style for the <body> tag should specify the font family to "arial" and the font size to "xx-large".  The style for the "boldRed" class should specify the font to be "red" and the font weight to "bold".  The style for the lightYellow ID should specify the font to be "yellow" and the font weight to be "light".  Test your style sheet by creating a page.

6.  What is the difference between an ID and a CLASS?

7.  List the style properties for controlling font.

LINKS AND HELP

http://www.w3schools.com/css/css_syntax.asp
http://www.w3.org/Style/CSS/learning
http://www.w3schools.com/css/css_reference.asp
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/css/reference/attributes.asp