More on CSS

We’ve already discussed the basics of Cascading Stylesheets. Let’s look at more. As mentioned in the first article on CSS, there is a concept of cascading preference, or priority. It works this way: A style embedded inside an html tag, an inline style has the highest priority. Next is a style defined in the head of an html page, an internal stylesheet. Last in priority is an external stylesheet, or .css file.

Let’s look at this idea: We’ve got a file, called page.html. It has a link to the stylesheet styles.css. In styles.css we have this style setup for the bold tag, <b>:

b {
font-weight: bold;
font-family: Arial, Tahoma, sans-serif;
font-size: 14pt;
}

Every instance of <b> will now have this style. What if we have a section in our html file where we’re using a serif font? Times New Roman, perhaps? It would look a bit strange to have the font-face change that drastically. Well, we could define styles in the head of the document. The internal stylesheet would override the complimentary styles defined in the styles.css file.

<head>
<style type=”text/css”>
b {font-family: Times New Roman, serif; font-size: 14pt; font-weight: bold;}
h1 {font-size: 18pt; font-weight: bold;}
</style>
</head>

Say we then have a portion of our document where we have a heading that has a bold section. We’ve defined the heading-one (<h1>) font-size as 18 point, but here we want the font-size to be 22 point. To do this in this situation, we add an inline style in the heading tag. This style would be valid for this single instance and would take precedence over the other two types of styles.

Example:

<h1 style=”font-size: 22pt;”>


Here are some online resources for CSS:

W3 Schools CSS Tutorials and Reference: http://www.w3schools.com/css/
Nice resource that has many of the CSS styles and attributes. Great place to go to learn the correct syntax for your attributes.
CSS Zen Garden: http://csszengarden.com/
This page shows the beauty of CSS when it comes to page design. There are several links on the side of the page. Each one loads the same content but styled with a different stylesheet.
css.maxdesign.com.au: http://css.maxdesign.com.au/index.htm
A resource for making lists and floating elements using CSS. A bit more advanced, but very useful and detailed examples.
A List Apart, CSS topics: http://www.alistapart.com/topics/css/
Articles dealing with uses of CSS. This one is my favorite: “From Table Hacks to CSS Layout: A Web Designer’s Journey. This details how a web site was redesigned using CSS.

This entry was posted on Monday, December 15th, 2003 at 4:24 PM and filed in Web Publishing, Knowledge Base. Bookmark this entry.