MSc-IT Study Material
June 2010 Edition

Computer Science Department, University of Cape Town

Classes

Sometimes you may wish to give different formats to different paragraphs in the same HTML document. This can be accomplished by using classes.

A classic example is the formatting of publications in journals, where the leading paragraph is an abstract and has the following format:

There are also many different formats for various other paragraphs. Each different paragraph type can be given its own class name, such as "abstract". To do this, we use the P tag as shown in the code below. Open a new file and type in the following code and save it as csexercise.css

p.abstract{
margin-left:4cm;
margin-right:4cm;
font-style:italic;
font-family:"times New roman";
font-size : 12pt;
text-indent : 1cm;
text-align : left;
}
.body{
margin-left:3cm;
margin-right:3cm;
font-family:"times New roman";
font-size: 12pt;
text-indent: 1cm;
}
     

Open a blank document and import the above style sheet. The abstract class is used as shown in the code below:

<P CLASS="abstract">

Exercise 5

As an exercise, add code to the stylesheet (csexercise.css) for the title, author, section heading and subsection heading. You can find the solution at the end of this chapter.

To Do

Visit Webmonkey's article "Inject Some Style (Sheets) into your HTML". Also visit the sites referred to at the end of the article.