Website Beginner for wanna be web designers

     


Let's Make CSS Style Sheets!

CSS style sheets in action

I'll start by giving you something to look at. It's a style:

.red { font-family: Times New Roman, Times, serif; font-size: 14px; color: #FF0000; }

This is a style I've named "red" (note the period before the word ".red" Don't leave it out). If we look at this we can see that I've defined the font family as Times New Roman, the size is 14 pixels and the color is red. This is text I've applied the style "red" to.

Now, in my web page, instead of putting the whole font tag song and dance in front of that last sentence, all I did was apply the style, by using the <span></span> tag. My source for it looks like this:

<span class="red">This is text I've applied the style "red" to. </span>

I didn't need to specify the type style or the size or the color because it's already in my style sheet, I just needed to tell it which style to follow. Tres cool, huh?

External style sheet or Internal?

You can put your styles directly in your webpage if you like. You'd put your styles in the Header and enclose them all in one set of style tags <style></style> like this:

<style>
.red { font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FF0000; }

tiny { font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 5px;}

</style>

But a waaaay better idea is to use an external style sheet, which is actually just a text file with all the css styles used in your website. Just create a regular text file, then stick your css in there (as in the first example) but instead of saving it as .txt, save it as .css. We'll call ours Styles.css, which we then link to our page by putting this in the Header:
<link href="/Styles.css" rel="stylesheet" type="text/css">

And voila! Instead of all those fonts tags that take up space in our web pages, we've just eliminated a lot of code. Now, every time the browser sees the span tag, it'll go to the Styles.css, find the style it needs, and apply it to the text.

Gotta love a good streamline and CSS style sheets do that with aplomb.

What's next? The magic and wonder of Server-Side Includes!



If you'd like us to alert you when new tutorials arrive,
join our email list (on the menu to the left)

You can email us at
Sorry, no individual questions answered,
though we may use yours as the basis for a new article.

©2009 www.WebsiteBeginner.com



HTML 101

HTML Tables
Text & Fonts
Web Graphics
Web Page Design
CSS & SSI
Web Hosting & Web Domains & Publishing
Search Engines & How To Make Money With Your Website

Our Book Store
Home

Tell a friend
about this site!


Join our email list for
article alerts and news.


Subscribe
Unsubscribe



Your email will not be
shared with anyone
and is ONLY for
use by this site.


Questions? Comments?

Privacy Policy