Home arrow Articles arrow Website Design and Marketing arrow The 30 minute CSS tutorial

The 30 minute CSS tutorial

CSS is the technology used to make the layout for webpages. They are Cascading Style Sheets, used to style your HTML documents. They are slowly replacing tables as the preferred medium to layout your pages. They free your content (the HTML document) from the layout (the CSS file), so you may change your website look and feel easily.

CSS basics.

With HTML, you would define the attributes as you write the HTML. With CSS, you first define the style. Then as you are writing the HTML, you apply the required style. So the first step to write CSS document is defining your styles. There are two ways to apply your CSS to your file. You may either include it in your HTML file by placing your stylesheet in head of your HTML as,

 



The Selectors.

After you write your style, the computer needs to know where to apply that style. This can be done using the selectors. The selectors are of three types.

1. HTML tag selector: If you want to change the look of any of your html tags, you will use this type of selector. You may decide that all of your h2 elements must have red text. It is trivially easy with CSS.
2. Class selector: you would like particular parts of your webpage to have a style, but that part is not always in same html tag. Not to worry, you can enclose that part with a div tag and apply your style.
3. ID selectors: If some element occurs only once it is styled using id selectors.

Your First Stylesheet.

With your first stylesheet, you will modify the page to look yellow with a blue foreground.







some text


The HTML part is simple, so let's look at the CSS part.

body{
background-color:yellow;
color:blue;
}

We wanted to modify the body so we used the body tag selector. This basically said to the computer that this style needs to be applied to whole body of html document. Then we used the background-color property to set the background and the color property to set the foreground. What if you wanted to set all the text to bold? Oh that's simple too, you just add this line inside the body selector. font-weight: bold;

Getting something useful.

The last css though simple was not very useful. Let us design a useful CSS which might be used on a site. Before that you must learn positioning elements using CSS. We would like to have a three column layout. So I will use three selectors(Id selectors) named sidebar, content and rightsidebar. Theses lines of codes declare our selectors:

#sidebar
#content
#rightsidebar

Then we will tell how these should look like. I want my sidebar and rightsidebar to have aqua colored background. This is done using background: Aqua;

Next we add borders to all our selectors and add a top margin of 20 pixels. We would like the contents to be bolder, so we add font-weight: bold; to content. After that we decide to spice up our links by making them of a different color and removing the underlines, by getting a color:#c60; text-decoration:none; To give the user a visual indication of the link when she moves her mouse, we swap the link colors. This is done by changing the style in a:hover.

So this is what our finished page looks like.









content
a link




What! Do I have to learn all these tags and attributes?

No. But you must remember the more important ones. Also the attributes have very common sense names. What should you do to change the background color of your webpage. Yeah this.

body{
background:Aqua;
}

That's all. SO if you are going to use CSS for any length of time, you will get to remember the tags. A css editor like TopStyle lite can be really useful when you are learning css.

Thats all for today. Hope you learnt something useful from this tutorial.

About the Author

Shabda Raaj is a free lance web designer and an avid blogger. His web design tutorials can be found here..

Website Hosting Companies, Buyer Beware

Friday, 14 December 2007 | Edward Cupler

article thumbnailWebsite hosting is probably the most important decision you'll make when launching a new website. The good news is that there are plenty of good low cost web hosting companies available to choose...
+ Full Story

Search Engine Optimization (They don't care what your website looks like.)

Sunday, 25 November 2007 | Edward Cupler

article thumbnailOptimizing your website for search engines is tricky. Some people think their website needs to be flashy to attract search engines. One thing I have learned over the years is search that engines...
+ Full Story

Video Raised the Internet Bar

Saturday, 16 September 2006 | Jim Hedger

article thumbnailby Jim Hedger The other day a few friends and I stopped back at the office after a long day of golf. By age, the foursome spanned three unique musical eras. Pete the chef is a child of the '70's....
+ Full Story

Why Aren't You Using Linkbait?

Sunday, 10 September 2006 | Kim Roach

article thumbnail by Kim Roach You've heard of the olden days when people would hunt for potential link partners. Well, those days are long gone and smart web masters are moving on to greater things, while...
+ Full Story

Top 7 SEO Tools

Sunday, 10 September 2006 | Kim Roach

article thumbnail by Kim Roach Search engine optimization is a complex process with many facets. Some of these include keyword research, on-page optimization, off-page optimization, acquiring inbound links, and...
+ Full Story

The most potent Internet marketing strategy

Sunday, 10 September 2006 | Blaz Banic

article thumbnailby Blaz Banic What would you call 731 new subscribers in a month and slowly falling, after having started with just 100? A great month? Fabulous outcome?
+ Full Story

Is Yahoo Under the Influence of TrustRank?

Sunday, 10 September 2006 | Kim Roach

article thumbnailby Kim Roach As you travel the vast world of search engine results among Google, Yahoo, and MSN, you are likely to run into junk pages at some point in your journey. Although the search engines are...
+ Full Story

How Not to Get Rich with Google Adsense

Sunday, 10 September 2006 | Al Hearn

article thumbnailby Al Hearn Those who desire to make money on the web ultimately find themselves looking at Google Adsense as one of the most promising methods of quickly seeing results.
+ Full Story

Copywriting With Google's Dynamic Keyword Insertion Tool

Sunday, 10 September 2006 | Karon Thackston

article thumbnailby Karon Thackston © 2006, All Rights Reserved Automation is an odd creature. It usually seems, at first glance, that automating a process can make things easier, simpler and faster. But...
+ Full Story

5 Fast Ways to Improve Your Website

Sunday, 10 September 2006 | Kate Ivy

article thumbnailby Kate Ivy Building a website is easy. Building a successful e-business is another thing altogether. How to make the most of your web presence? Here's five easy tips to maximize your site.
+ Full Story

The 30 minute CSS tutorial

Sunday, 10 September 2006 | Edward Cupler

article thumbnailCSS is the technology used to make the layout for webpages. They are Cascading Style Sheets, used to style your HTML documents. They are slowly replacing tables as the preferred medium to layout...
+ Full Story