to expand the possibilites of a website in terms of color, style, positioning and whatnot. It's a very simple scripting language (or markup language if you will ),
that has no other purpose than to add style to a website.
Now, let's get into the process of using CSS in webpages. Let's start off with the
ways CSS can be used. It can be used in three ways: a) through the current page,
b ) through an external .css file and c) through the style attribute in any HTML
element. I'll be focusing on the first one in this tutorial only.
This is how it would be written. But don't worry, I'll explain what it all means.
CODE
<head>
<style type='text/css'>
<!--
//Style properties go here
-->
</style>
</head>
Now, this is the set up of every css that you use within the current page. The <head> tag should be recognizable to you. The STYLE tags let you create a
stylesheet within the webpage's HEAD tags (always remember to put stylesheets within the HEAD tags).
A stylesheet is just a set of style properties as you will see. The 'type=text/css' component makes sure that the Browser reads the text as CSS and not as HTML. Okay, you now maybe wondering what these <!-- --> are for. Well, this is an old practice done by many specifically for users with older browsers. Older browsers can not read CSS, so some use those <!-- --> to "comment" out the code. That means that the Browser does not look at that code. It just continues interpreting the HTML code (this same procedure applies to Javascript as well).
Now that you have the format down pat (well I hope you do), let's move on to some actual style properties. Here is a small example:
CODE
<head>
<style type='text/css'>
<!--
BODY { background-color: black; font-family: Arial; font-size: 10; }
TABLE { background-color: #555555; }
-->
</style>
</head>
Here we have two html tags, BODY and TABLE. But they aren't tags. They are referred to as elements. These elements have been given several properties.
As you can see, there are a number of properties inside these elements.
A property is basically the same as an attribute in HTML. The only difference is that properties are assigned values without an equal sign. Instead, a colon (
these either, or else your stylesheet will not work.
Now, the BODY element contains three properties: background-color, font-family,
and font-size. I'm assuming that you know what these mean, so I don't really need
to explain them. The TABLE element contains one property - background-color.
The BODY and TABLE's properties are global - this means that all HTML tags,
including BODY and FONT, will take on the same properties as these two elements. This can be a blessing and a curse. Unless you use classes (which I will get into soon), everything within the body of the page will take on those font properties. And the same goes for the tables. Every table used in an HTML page will have the same background color.
But what if you want more flexibility? What if you want to have different tables with
different colors and different fonts? Well, this is where classes come in. Classes are basically sets of properties that don't effect all HTML tags in a webpage -
but effect specific tags. Think of a class as a set of traits. Each human has a set of traits. One human can draw, write fast, swim, while another can run fast, read quickly, and dance. The traits are the properties. I hope I didn't lose you there.
Here's an example of a class:
CODE
<head>
<style type='text/css'>
<!--
.myfirstfont { font-family: Verdana; font-size: 10; color: blue; }
.mysecondfont { font-family: Arial; font-size: 12; color: red; }
.mythirdfont { font-family: Tahoma; font-size: 16; color: green; }
-->
</style>
</head>
Okay, there are three classes in this code. Each class in this code (myfirstfont, mysecondfont, mythirdfont), set aside a number of properties for any specific HTML tag. These would most likely be used in FONT tags, but that's not important
right now. You understand what these properties mean, so now what? At this point,
these are useless. Utterly useless. For them to be of any use, you'll have to embed
them into HTML (don't worry, it's not hard). Here is a sample HTML page that
embeds those three classes into FONT tags:
CODE
<html>
<head>
<style type='text/css'>
<!--
.myfirstfont { font-family: Verdana; font-size: 10; color: blue; }
.mysecondfont { font-family: Arial; font-size: 12; color: red; }
.mythirdfont { font-family: Tahoma; font-size: 16; color: green; }
-->
</style>
</head>
<body>
<font class="myfirstfont">Here is my first font.</font><br>
<font class="mysecondfont">Here is my second font.</font><br>
<font class="mythirdfont">Here is my third font.</font>
</body>
</html>
Take a look at those three lines of HTML between the BODY tags. There are
three FONT tags used. Now, the three classes we made earlier have been embedded into the HTML. You do this by using the CLASS attribute as shown
above.
I hope this tutorial was of use to you. It's purpose was to introduce the basics to those just starting off in web design.
I've provided a list of CSS properties. If you want to learn what these properties
do, plus many other properties, visit http://htmlgoodies.com/beyond/css/cssref/.
text-align, text-decoration, text-transform, font-family, font-size, color, font-weight
font-style, margin-left, margin-right, margin-top, margin-bottom, background-color
background-image, vertical-align, align


