Creating a CSS File for your Web site
Dave Berry wrote an excellent article about Cascading Style Sheets (CSS) on MSDN (Using Cascading Style Sheets on Your Web Site), so I won't bore you with the details of CSS. However, one reader commented that the article didn't cover how to create an external CSS file. This is very easy, so here's how.
Say you have the following embedded style sheet on a page and you want to share the styles with other pages in your site. (See "Three Types of Cascading Style Sheets: External, Embedded, and Inline" in Dave's article.)
<style>
BODY
{font-family: Comic Sans, Verdana, Tahoma, Arial;
font-size: 10pt;
margin: 0em;}
P
{padding-left: 5;
padding-right: 5;}
H1
{font-size: 11pt;
font-weight: bold;
color: white;
background: #FF3399;
padding-top: 10;
padding-bottom: 5;
padding-left: 10;
padding-right: 10;}
</style>
All you do is copy the contents of the STYLE element (the text between the tags but not the tags themselves) into a new file. (In FrontPage 2003, you can create a new blank page, display the page in Code view, and paste the CSS code. In earlier versions, you can either use HTML view or Notepad.) Then save the file with a .CSS extension. I usually call the main CSS file for a Web site web.css just for the sake of consistency, but you can name it anything you want.
The contents of your new file should look something like this:
BODY
{font-family: Comic Sans, Verdana, Tahoma, Arial;
font-size: 10pt;
margin: 0em;}
P
{padding-left: 5;
padding-right: 5;}
H1
{font-size: 11pt;
font-weight: bold;
color: white;
background: #FF3399;
padding-top: 10;
padding-bottom: 5;
padding-left: 10;
padding-right: 10;}
Once you have the CSS file, you can remove the STYLE element and it's contents from the first page, and add a LINK element or an @Import statement. I rarely have more than one CSS file for a Web site, so I generally use the LINK element (like the one shown below).
<link rel="stylesheet" type="text/css" href="web.css">
But if you anticipate using more than one CSS file in a Web site, you can use the @import statement, as shown in the following code:
<style type="text/css">
@import url(web.css);
@import url(page.css);
</style>
Dave gives a great explanation of the difference between these two and what happens if two styles conflict with each other.
It really is that simple. Deciding which styles to use is much more difficult. I (personally) like the CSS attribute reference list on MSDN, but keep in mind that some of the CSS attributes listed are IE only (like the scrollbar styles). Plus, there are literally dozens of online CSS resources. Here are just a few that I found through the new MSN search. Try your own search and find your own CSS resources.
Comments
- Anonymous
February 01, 2005
The comment has been removed - Anonymous
February 01, 2005
Visual Studio .NET 2003 has an excellent CSS editor
http://moskalyuk.com/blog/my-favorite-css-editor-visual-studio-net/330
Another great one is Firefox WebDeveloper toolbar, allowing CSS modifications on the fly.
https://addons.update.mozilla.org/extensions/moreinfo.php?id=60 - Anonymous
May 11, 2005
The comment has been removed - Anonymous
May 19, 2005
Just a comment to Jim: CSS will default to pixel measurement if a measurement type isn't noted. So the code
padding-left: 5;
actually means:
padding-left: 5px;
This works across all the browsers I've tested it against, which is to say all major browsers. Perhaps that's not the way we're taught, it is the way it works. - Anonymous
May 20, 2005
The comment has been removed - Anonymous
September 30, 2005
The comment has been removed - Anonymous
October 02, 2005
ummmmmmmmm whats this mummy?? http://gobkind.250Free.com/internet-merchant-accountnational-city-bank.html - Anonymous
October 02, 2005
This is a very influential speculative novel of http://gobkind.250Free.com/internet-merchant-accountnational-city-bank.html - Anonymous
October 06, 2005
The comment has been removed - Anonymous
October 08, 2005
The comment has been removed - Anonymous
October 10, 2005
Het begint op een vendetta te lijken, dat geeft niet hoor maar Dr. Phil zou zeggen http://gobkind.250Free.com/internet-merchant-accountnational-city-bank.html - Anonymous
October 11, 2005
Hehe, ik dacht ook meteen aan dat beetje invloed op http://gobkind.250Free.com/internet-merchant-accountnational-city-bank.html - Anonymous
January 23, 2006
The comment has been removed - Anonymous
February 01, 2006
The comment has been removed - Anonymous
February 03, 2006
The comment has been removed - Anonymous
February 13, 2006
Welcome!!! http://www.pr.com/contacts/">http://www.pr.com/contacts/ google pr. [URL=http://www.pr.com]pagerank 5[/URL]: Search Engine Optimization, Professional SEO, pagerank algorithm. Also [url=http://www.pr.com]online pr16[/url] from google pr . - Anonymous
February 13, 2006
hello! http://www.pr.com/contacts/ google pr. Search Engine Optimization, Professional SEO, pagerank algorithm. From google pr . - Anonymous
March 14, 2006
The comment has been removed - Anonymous
April 24, 2006
The comment has been removed - Anonymous
April 28, 2006
Fill free to make more posts. It is interesting. - Anonymous
June 19, 2006
interesting stuff ! ! ! ! - Anonymous
June 23, 2006
Best of all people w can talk... - Anonymous
July 02, 2006
The comment has been removed - Anonymous
July 16, 2006
clear pores - Anonymous
September 19, 2006
Please, follow this link:
[url=http://trazodone.dostweb.com/ trazodone.html]trazodone[/url] [url=http://trazodone.dostweb.com/ trazodone_side_effects.html]trazodone side effects[/url] [url=http://trazodone.dostweb.com/ trazodone_hcl.html]trazodone hcl[/url] [url=http://trazodone.dostweb.com/ trazodone_weight_gain.html]trazodone weight_gain[/url] - Anonymous
September 20, 2006
Look this:
[URL=http://flexeril.darkbb.com]flexeril[/URL]
[URL=http://trazodone.darkbb.com]trazodone[/URL]
[URL=http://lisinopril.darkbb.com]lisinopril[/URL] - Anonymous
September 23, 2006
Tabblets! No prescription!
September DISCOUNTS!!!
http://avandia.darkbb.com
http://fluoxetine.darkbb.com
http://metformin.darkbb.com
http://lisinopril.zikforum.com
http://metoprolol.darkbb.com
http://zocor.darkbb.com - Anonymous
September 24, 2006
I have learned more on this one page than the combined knowledge perched upon hundreds-of-millions of the rest of the pages on the Wide Wacky World Webaroni thingy