Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

An Introduction to CSS

pages (2): [1] 2


If you are a web designer and haven't been living in a cave for the last few years, then you must have heard of the amazing CSS technology! CSS is short for 'Cascading Style Sheets', and is a part of current web standards. Quite simply, it allows you to define your entire design from one simple document, making templates an utter doddle to set up and maintain.  To help you get to grips with the new technology, this tutorial covers the basics of CSS setup, and helps get you well on your way to a more complete understanding of the CSS methodology.


Section 1: The Basics
Style sheets come in two distinct flavours - internal (i.e. the CSS definitions are part of the source HTML document), and external (i.e. All CSS definitions are in a separate file).  For the sake of this tutorial we will be exploring external stylesheets only.  All you need are two files - yourfile.html and yourfile.css.  Put your CSS definitions in the .css file as simple text, and the HTML in the .html document. Section 4 will tell you how to link the files together.

body{ background-color:#000000; }

This small snippet is the CSS code to change the background color of your web site. Looking at it, we can break it up into a number of different components:

  1. 'body' - This tells the browser what is going to be affected. Using 'body' means that all <body> tags will have this style. This can be changed to any html tag. To have it apply to multiple tags separate each with a ','. Eg. body, font, td

  2. '{' and '}' - The curly brackets encase all of the attributes assigned.

  3. 'background-color:' - 'background-color' is one of the many CSS attributes. It defines the objects background color, similar to the HTML attribute 'bgcolor'. Notice that it is followed by a colon ':'. All CSS attributes will have this colon.

  4. '#000000' - This is the user-defined part of the attribute. Enter any six digit hexadecimal color value here. #000000 will produce a black background.

  5. ';' - The semicolon is very important. It is the closing tag for all CSS attributes and is needed the browser to tell when old attributes end and new ones begin.

Here is another example showing the syntax for using more than one attribute:

body{ background-color:#000000; font-family:Arial, Helvetica, sans-serif; font-size:12px; }

 

Section 2: The Class
If you want to define unique sets of variables for various uses (i.e. a 'bigtext' class for headings, and a 'specialtext' class for important text sections), then you will have to make use of classes.  These are defined as follows:

The CSS:

.bigfont{ font-family:Arial, Helvetica, sans-serif; font-size:40px; }
  1. '.' - The dot says that you are starting to declare a class.
  2. 'bigfont' - This is the user-defined name for the class. Call it whatever you want.
  3. '{font-family:Arial, Helvetica, sans-serif; font-size:40px;}' - As with example 1, these are the user-defined attributes enclosed by curly brackets.

The HTML:

<font class="bigfont">This is big text.</font>

Now I'll explain CSS classes. Here is a rundown of the different components:
  1. 'class="bigfont"' - Here is where you select the class you want to use (and, hence, what attributes you want to apply to the font).

Classes are very useful because they can be used an infinite number of times, and can apply to whatever HTML tag takes your fancy (unless, of course, you declare attributes for a specific tag, which will be explained later).  Just to make sure you have been listening, though, here's a few more examples:

Example 1:

<td class="bigfont"> <font class="bigfont">This is big text inside a <td> with the same class applied.</font> </td>


Example 2: Here is an example of a class made specifically for a <font> tag. Notice the only difference is the preceding word 'font' before the '.'.

The HTML:

font.bigfont{ font-family:Arial, Helvetica, sans-serif; font-size:40px; }

The HTML:

<font class="bigfont">This is big text.</font>

- Tutorial written by Gus Mayo

Pages (2): [1] 2 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments

User:  robin746 (#27062)
Date: Tue May 02, 2006. 20:10:38

Post #1 of 1

This is a good tutorial to get people's feet wet in CSS. I like the layout but would suggest splitting lines at the semi-colon. Having one style per line really helps readability.

I have one criticism though in the example you choose, namely bigfont. Though technically valid it goes against the whole CSS concept of separating semantics from style. A designer should ask themselves why they want a font bigger. Normally this is because it marks a section, chapter, or some other structural entity. In this case, use the appropriate header tags (H1, H2, H3...). That's what they are for!

This not only saves having to define your own class, but it provides consistent information for screen readers, search engines, and other non-visual browsers of your page.

I never use the HTML font tag. It's presence is generally a good indication that the design is wrong.

Reply to this post


--- View Entire Thread ---
Amazing Font Pack!

Featured Tutorialsmore

Airbrushing On Pho...
Airbrushing On Pho...
- Adobe Photoshop -
Artificial Rainbows
Artificial Rainbows
- Adobe Photoshop -
Simple Painterly E...
Simple Painterly E...
- Adobe Photoshop -
Sinedots
Sinedots
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 880 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1044 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1049 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1927 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1824 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14435 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2741 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2769 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3434 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2352 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2494 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2796 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673