CSS is a way to add style to a document quickly and easily. It's the reccomended way to do this for several reasons:
The basic structure of CSS is esentially a list of styles. There are complicated rules about cascading, but those won't be looked into much during this tutorial. A typical stylesheet looks like this (only longer):
body {
margin: 0px;
padding: 5px;
background-color: #9091A8; }
#header {
height: 100px;
margin-bottom: 5px;
background-color: #D1EDC4;
border: 2px solid #000; }
.blocktext {
border: 2px solid black;
padding: 3px;
margin: 0px;
margin-bottom: 5px;
background-color: #fff; }
.minicontaincenter p a { text-decoration: none; }
There are a few ways of defining styles; these are known as "selectors." the selectors in the example above are seen before the opening bracket ( { ). A few types of selectors are:
In general, classes are used for elements that may occur more than once in a document, and IDs are used for elements that only occur once in a document. That's why we used an ID in the three sections of XHTML document made in lesson 1. We could have used classes for those sections without a problem, but using IDs makes it easier to maintain the stylesheet. In places you use classes, however, you can not use IDs. Using IDs in place of classes can lead to problems in some cases. Most often these problems only show up in validators. This lesson will not be looking at the basics of CSS itself, but rather will walk you through the basics of making a CSS layout for a web site. Lesson 3 will look closer at the basics of CSS styling.