As discussed in the previous tutorial, Cascading Style Sheets (CSS) provide a convenient way to create a uniform appearance of several web pages within the same web site. Various characteristics such as font, font sizes, margins, and colours can be specified on a master file, then each Web page refers to this list, with the styles "cascading" through the page or the entire site.

This tutorial will move through various steps and experiments to see the behaviours and capabilities of CSS.

<html>
<head>
<title>Page 1</title>
</head>

<body>
<div id="cont1">Container 1</div>
<div id="cont2">Container 2</div>
<div id="cont3">Container 2</div>
<div id="cont4">Container 4</div>
</body>


</html>

  Using Notepad, TextEdit, or other plain-text editing program and create the file on the left. Make sure that you name it with a ".html" extension, (ie. page1.html)

The div id tags will encapsulate whatever styles are outlined in the stylesheet file to be added shortly.

Click here to view  Pretty plain looking, isn't it?

Fig.1


#cont1 {
            background: #ff0000;
            position: absolute;
            top:20px;
            left:20px;
            width:300px;
            height:200px;
            }

#cont2 {
            background: #00ff00;
            position: absolute;
            top:20px;
            left:320px;
            width:300px;
            height:200px;
            }

#cont3 {
            position: absolute;
            background: #0000ff;
            top:220px;
            left:20px;
            width:300px;
            height:200px;
            }

#cont4 {
            position: absolute;
            background: #ffff00;
            top:220px;
            left:320px;
            width:300px;
            height:200px;
            }
 

Create a second file with the information shown in Fig. 2 to the left. Name it style1.css

#cont1, #cont2, etc. define the properties of the respective <div id tags in the html file.

In your first file, (page1.html or whatever you named it), add the reference to the stylesheet file:

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

<html>
<head>

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

<title>Page 1</title>
</head>

<body>
<div id="cont1">Container 1</div>
<div id="cont2">Container 2</div>
<div id="cont3">Container 2</div>
<div id="cont4">Container 4</div>
</body>


</html>

Fig. 3

Click here to see how the new styles affect the original page.

Fig. 2


#cont1 {
            background: #ff0000;
            position: absolute;
            z-index 3;
            top:
20px;
            left:
20px;
            width:300px;
            height:200px;
            }

#cont2 {
            background: #00ff00;
            position: absolute;
            z-index 2;
            top:
40px;
            left:
40px;
            width:300px;
            height:200px;
            }

#cont3 {
            background: #0000ff;           
            position: absolute;
            z-index 1;           
            top:
60px;
            left:
60px;
            width:300px;
            height:200px;
            }

#cont4 {
            background: #ffff00;
            position: absolute;
            z-index 1;
            top:
80px;
            left:
80px;
            width:300px;
            height:200px;
            }
  Open the css file, (style1.css) and make the changes as shown to the left. Keep the original version of the css file so you can change back and forth to review the differences.  Make the new copy by going Save as... and naming the new file style2.css.

z-index  sets the layer order of the containers, with the higher number being closer to the top.

Make the change in the page1.html file as shown below.

<html>
<head>

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

<title>Page 1</title>
</head>

<body>
<div id="cont1">Container 1</div>
<div id="cont2">Container 2</div>
<div id="cont3">Container 2</div>
<div id="cont4">Container 4</div>
</body>


</html>

Fig. 5

Click here to see the changes.

Fig. 4


#cont1 {
            background: #ff0000;
            position: absolute;
            top:
20px;
            left:
20px;
            width: 300px;
            height: 200px;
            }

#cont2 {
            background: #00ff00;
            position: absolute;
            top:
220px;
            left:
20px;
            width: 300px;
            height: 200px;
            }

#cont3 {
            background: #0000ff;           
            position: absolute;
            top:
420px;
            left:
20px;
            width: 300px;
            height: 200px;
            }

#cont4 {
            background: #ffff00;
            position: absolute;
            top:
620px;
            left:
20px;
            width: 300px;
            height: 200px;
            }
 

Make the change in the page1.html file as shown below.

<html>
<head>

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

<title>Page 1</title>
</head>

<body>
<div id="cont1">Container 1</div>
<div id="cont2">Container 2</div>
<div id="cont3">Container 2</div>
<div id="cont4">Container 4</div>
</body>


</html>

Fig.7

Click here to see the changes.

Fig. 6


Place the following five lines at the top of the style3.css file:
body   {
            background-color: #000000;
            font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
            color : #000088;
            }
Fig. 8

Click here to see the changes.