CSS - Quick Start

CSS stands for Cascading Style Sheets.  They are so called because styles cascade down through the elements.  For example, you might have a bold word inside a paragraph inside a table on a page.  Any style you apply to the whole page, such as a font, will also apply to the table, the paragraph and the word because they are all inside the page.

Style information can be included at the top of the page using <style> tags, or it can be linked to from a separate file.  Having your style in a separate file means that you can style your whole web-site from one place, and each individual page is smaller and quicker to load (as the stylesheet can be cached).

Example

<style>
body    {font-face: Arial; color: #AA0000; background-color: white}
p	{text-align: justify}
.warn	{color: red}
#foot	{font-style: italic}
</style>

What does this do?  Well, it makes the whole page use the Arial font, with a foreground colour of dark red (#AA0000) and a background colour of white.  It makes all paragraphs justified.

So, if you use an HTML tag name in your styles, the style applies to all elements of that type - e.g. the p style applies to all paragraphs.

The . prefix indicates that that style applies to a class, and to use that style I need to add a class attribute to an HTML element, e.g. <p class="warn">...</p> will create a red paragraph.  You can have many elements with the same class, but not all paragraphs will be red.

The # prefix indicates that that style applies to an id.  An id must be unique within the page, so this style will only ever be used once - although it can be used on other pages.  An element with the tags <p id="foot">...</p> will create a paragraph with italic text.

There are lots of different things that can be changed with CSS, from margins and border thickness, to rounding corners and setting semi-transparent colours. There are other pages showing you how to create rollovers, menus and animations using CSS.

Next page...