HTML Cookbook Basic HTML Course

It's Easy!

Alternate version

CSS Step By Step

Getting Started

To use CSS, we need to learn what is looks like, its proper forms and where to put it on a web page. We'll start with the CSS statement.

CSS Statement

One of the cool things about CSS is that we get to define how our pages look. This is what style is all about. One of two ways to define style is with CSS Statements. The other way is to use Style Declarations, which we'll cover in the next lesson.

Here is the style statement form:
property: value

A property is the same as an attribute. The value is just the value we gave to that property. A colon goes between the property and the value. The spaces are optional, but they make the code easy to read.

So we'll use CSS style statements to replace some attributes and their values.

Instead of
attribute="value"
we'll simply use
property: value


Example

We are all familiar with the body tag, which uses attributes paired with values to determine the look of a page. We can think of these pairs as "attribute statements".

In CSS, we will replace attrbute-value pairs with style statements, such as the following
bgcolor="#000000" will be replaced by background-color: #000000
text="#ffffff" will be replaced by color: #ffffff
align="center" will be replaced by text-align: center

To use a style statement in an element (tag), we combine with the word "style" like so:
style="property: value"


Multiple Properties

Just as an HTML tag may have more than one attribute, you can apply more than one style to an element. The property-value pairs are then separated by a semicolon, like so:
style="property1:value"; property2:value"

As we go along, we will learn how to use CSS in three places:

In-line style in an element

Let's start using style statements right away by placing one in a paragraph. Just use a style statement right in a paragraph tag. Here are two examples.

<p style="color: #0000cc">I feel blue.</p>
The text in this paragraph will be blue (#0000cc)*.

<p style="text-align: center">This text is centered.</p>
The text in this paragraph will be centered.


Assignment

On your sampler page, write a paragraph using a style statement in a paragraph element (tag). Post your page or your paragraph code and any questions in this thread.

In our next lesson, we'll discuss CSS style declarations and stylesheets. We will also develop a list of properties to replace attributes as we go along.

Happy coding!
Gnubee

Links
Tips
Tools
References
Rules
HTML Help Gnubee - Newsgroup
HTML Course Contents (Home)

Valid XHTML 1.0!

Valid CSS!