Basic CSS Tutorial

Note: The examples that are used in this tutorial will be opened in a new window!

This is a tutorial about the basics of CSS (Cascading Style Sheets). It's handy if you have some knowledge of HTML. 

Introduction
CSS is the most important mark-up language for webmasters. CSS is a mark-up language for web pages and so it isn't a scripting language.

What's so important about CSS? And why should you bother to learn it?
There are several reasons to do it! Here some short ones:

The only reason why you shouldn't use CSS is because you don't know it yet!

Syntax
Also CSS has specified syntax. These are the rules you need to follow by writing CSS.

Every reference of CSS consists of at least 3 parts.

CSS syntax:
selector {property: value;}

Properties
It's also perfectly possible to assign multiple properties to 1 selector.
Like a text in bold and in italics. We separate all the properties for this from each other with ; .

CSS syntax:
body {property1: value; property2: value; property3: value;}

The selector
This part indicates where the lay-out of the text or style block is located. These location can be addressed on 3 different possible ways.

Commentary
It's also possible to write commentary between your CSS code that later on can help you find back specified styles. This is especially important when you use long and complex CSS codes. You may place this commentary between different styles or between the different properties.

CSS syntax:
<style type="text/css">
selector1 {property: value;}
/* Here you can write your commentary */
selector2 {property: value;}
</style>

or

CSS syntax:
<style type="text/css">
selector {
property1: value;
/* Here you can write your commentary */
property2: value;
}
</style>

How do you put the CSS codes on your web page?
There are two methods to put your CSS codes on you web page. The two ways are:

Attention, please!
You can use this different methods at the same time, but the method the nearest by the lay-out of the tag has priority. The general rule is that Inline CSS has priority to a Style tag and this on his turn has priority to the External CSS file.

Beginner
Now that we've seen how we apply a CSS style to a document, can we explain the further possibilities. These are especially the different properties. With each property we give an example so that can get the hang of everything in a practice kind of way.

Font types
To change the font type we have several properties, think of size, type, color, ..... Below you find a list of the most important properties.

Text lay-out
We can now adjust every font type in a defined text but we may not forget to lay-out the text itself. Business like aligning, line height, ... are just as important in the lay-out of a piece of text.

Color and Background
Now we've done the lay-out of the font type we can go on with the next step the colors. in CSS not only the color of the font can be altered, but almost of every object. So also for buttons, backgrounds, tables, .....

Borders
The borders of a text, cell, button, ... are handled extensively in CSS. You can choose different styles, width, colors and many more.

You can also use all these properties 1 border of a framework or a combination, like for the top: border-top-style or border-top-color. This is the same for left, right and bottom.

Margin
Now that you can put borders around an object you must also know that you can also define the distance from the borders to the content. Not to only the content, but also the margin facing the surrounding objects. For this there are 2 specific properties (padding and margin).

Advanced
Here you will learn to use positioning and other less known CSS properties.

Positioning
CSS makes it possible to position all objects on a personal manner with absolute and relative positioning.

Special
Here you see how you can adjust the scrollbar (As far as I know is this not supported with every browser. I believe it's only supported in Internet Explorer 5.5 and above. That's also the reason why I've put it in a special section of the tutorial).

Scrollbar coloring
I'll show the attributes that are available for the coloring of a scrollbar in the image beneath.

The values of the attributes can be defined as a Hexadecimal value or a standard color.
Beneath you see the CSS syntax to color the scrollbar.

CSS syntax:
body{
scrollbar-face-color: #000000;
scrollbar-highlight-color: #2E55AF;
scrollbar-shadow-color: #888888;
scrollbar-3dlight-color: #FFFFFF;
scrollbar-arrow-color: #FFCC33;
scrollbar-track-color: #336699;
scrollbar-darkshadow-color: #333333;
}

You can see an example of this here.

Click here to go to the Property List of CSS.

Copyright © HF OADA. All rights reserved.
This page is updated till Monday 24 May 2004