CSS Introduction


 

What is CSS?
• CSS stands for Cascading Style Sheets
• CSS Styles define how to display HTML elements such as fonts, tables, backgrounds etc
• Styles are normally stored within Style Sheets
• Styles were added to HTML 4.0 to solve a problem
• External Style Sheets can save you a lot of work
• External Style Sheets are stored in CSS files
• Multiple style definitions will cascade into one

Why Use CSS?
CSS is a godsend for web designers because it saves so much time. CSS enables us to style elements in our website such as the font - i'll give you an example. Before CSS if a client rang you and suggested changing the main font that ran throughout your site you would have to go through and manually change that font yourself. With CSS you dont have to. As long as you have applied a 'style' to that font you can simply change the font type in your CSS file and the change will be seen throughout your site - not just on one page. Thats the basic idea behind CSS as it enables you to do things that old school languages such as HTML dont. Web design for me personally doesnt stop once you've designed your layout in Photoshop, it continues into Dreamweaver. Making a page look good in Dreamweaver was difficult to acheive, but with CSS you can control the look of your actual content.

What does CSS look like?
Basic CSS is pretty easy on the eye and doesnt take that much brain power to grasp! Below is an example of a stylesheet which includes values for 'bodytext' and 'bodylinks'

<style>
.bodytext {color: #4d4b4c; font-family: arial; font-size: 12px; line-height : 100%; font-weight: none; text-decoration: none;}

.bodylinks A {font-size:12px; color: #ff9900; font-family: arial; font-weight: none; text-decoration: none;}
.bodylinks A:link {font-size:12px; color: #ff9900; font-family: arial; font-weight: none; text-decoration: none;}
.bodylinks A:visited {font-size:12px; color: #ff9900; font-family: arial; font-weight: none; text-decoration: none;}
.bodylinks A:active {font-size:12px; color: #ff9900; font-family: arial; font-weight: none; text-decoration: none;}
.bodylinks A:hover {font-size:12px; color: #666666; font-family: arial; font-weight: none; text-decoration: underline;}
</style>

To get to grips with CSS its really a trial and error process so its best that you get stuck in and start messing about with styles.

Including CSS in your web site
For organisational purposes the best way (and the way i will show you) to use CSS is to link to an external file. This simply means that you dont include your CSS in your HTML files - the reason for this is that it improves loading times and its neater to store all CSS in one location.

Attatching StyleSheets
Its easy to apply a style sheet. Especially if you have Dreamweaver! To attach the CSS do the following.
1. Open your site in Dreamweaver
2. Go to TEXT > CSS Styles > Attach Stylesheets
3. Locate the CSS document on your computer
4. Dreamweaver will recognise all the styles in the sheet. To add one go to Window > CSS Styles.
5. Highlight your text, and then click on the name of the style you want to apply and bingo!

If you dont have the luxury of Dreamweaver you can attatch the stylesheet manually. Just add the code you see below to any pages you want to use your CSS on. Make sure it goes inside the <head> tags.

<link href="yourstylesheetslocation.css" rel="stylesheet" type="text/css">

I hope you found this tutorial a useful introduction to CSS. Please head on over to CSS2 RFC for a more indepth explanation, quiz and more on CSS.

Vertical Drop Down CSS Menu