<p>Notice<br /> The Page Has Not Loaded Properly.<br /> While Holding The Cmd Key Down,<br /> Tap The R Key 5 To 7 Times.</p>

CSS Notes

Cascading Style Sheets
Wazcal Is Here
HTML Help Gnubee
(Home Of The Mallrats)


Introduction

This is a basic presentation for Webtv users to become familiar with CSS and help make their pages more cross browser compatible and more compliant with the latest W3C HTML specifications. There is much more to Cascading Style Sheets than what you will find here. Some of the properties and values known to be compatible with Webtv (2.8.2) are included. There are definitely more. To become more familiar with CSS, visit the W3C CSS Pages with the links provided.

Not all examples given are practical. They are there to make a point.

None of the examples include the appropriate document type, character set or name space information as required by the W3C Specifications.

It also should be noted that a tag is not an element. An element normally includes a start tag, content and an end tag. Except those elements that are defined as normally open.

Getting Started

The foundation of CSS is the rule:

selector { declaration }

A declaration contains a property and a value:

selector { property: value }

Notice the curly brackets ( { } ) surrounding the declaration, and the colon ( : ) separating the property from the value.

Selectors and declarations can be grouped:

selector, selector { property: value }

selector { property: value; property: value }

selector, selector { property: value; property: value }

Notice the coma ( , ) separating the selectors and the semicolon ( ; ) separating the declarations.

The selector is the connection between the style sheets and the body of the page. The selector can be most HTML element types. A sampling of some of them that work with Webtv 2.8.2 are:

body, h1, h2, h3, h4, h5, h6, p, b, i, ol, ul, li, table, td, big, cite, del, dfn, em, img, ins, kbd, pre, small, samp, s, sub, sup, tt, u, var, anchor pseudo-classes (link, visited link and active link).

The <div> (block) and <span> (inline) provide a generic means of adding style sheet properties and values with class and id, or inline.

The basic properties and values are similar to what we're already used to, except that they're formatted differently. Allot of them reference color, size, style, family, alignment, margin, weight etc. There are however, many more we can use with CSS. Also, we can make changes to some elements that we never could without CSS.

Take the body as the selector for example. We can start out with the basic background and text information:

body {
background-image: url(urloftheimage.jpg);
background-color: #ffffff;
color: #000000;
}

In this example we're calling for a background image (urloftheimage.jpg) which would be the image of your choice, a background color of white (#ffffff), and a text color of black (#000000). We can simplify the background declarations by using the shorthand method. (Not all shorthand methods work with Webtv, it's a matter of trying them out).

body {
background: url(urloftheimage.jpg) #ffffff;
color: #000000;
}

Also, there is no set way of arranging the rules. I could have just as easily done it this way:

body { background: url(urloftheimage.jpg) #ffffff; color: #000000; }

Or this way: body{background:url(urloftheimage.jpg)#ffffff;color:#000000;}

However, it's always best to write code in a way that's easy to read, understand and edit.

There are parent/child relationships involved here. Every property and value we put in the body element will effect all the elements on the page, because in this case the body is the parent and all other elements are the children. We can change that for each element by giving them their own set of properties and values. For example, a page title:

h1 {
color: #dc143c;
font-size: 27pt;
font-weight: normal;
text-align: center;
}

Here I've changed the color to crimson, made the font size larger (27pt which equals size 6), removed the bold that the <h1> through <h6> elements have, and center aligned it. Now every time I use <h1> it will have these properties and values.

This process can be continued for every element on the page by addressing each element with it's own properties and values.

p {
color: #00008b;
font-size: 23pt;
text-align: center;
}

Now all text within <p> and </p> will be dark blue, 23pt (size 5) in size and center aligned.

We can also use comments, which are basically notes and reminders to help keep style sheets organized. Comments will not be displayed on the page.

This is a comment example:

/*main title*/

We connect these rules to the body of the page by simply using the elements used as selectors.

The embed method is a very common way of adding and learning style sheets, where you put the code between the </title> and </head> tags.

This is an example (without a background image), where

<style type="text/css"> is the opening tag,
<!-- and --> are comments that prevent browsers from displaying the code,
and </style> is the closing tag:

<html>
<head>
<title>CSS Example</title>
<style type="text/css">
<!--

body {
background: #ffffff;
color: #000000;
}

/*page title*/
h1 {
color: #dc143c;
font-size: 27pt;
font-weight: normal;
text-align: center;
}

/*larger and centered text*/
p {
color: #00008b;
font-size: 23pt;
text-align: center;
}

-->
</style>
</head>
<body>
<h1>Page Title</h1>
The body text is here.
<p>The larger and centered dark blue text is here.</p>
</body>
</body>
</html>

Which would look like this:

Page Title

The body text is here.

The larger and centered dark blue text is here.



Contextual Selectors

Contextual selectors are conditional. Simply put, if a condition exists then the declaration(s) will be implemented.

selector selector { property: value }

Notice the white space between the selectors.

For example, if you want all emphasized text within bold text to be blue, you could do this:

b em { color: #0000ff; }

Then in the body of the page you could put:

<b>I can't <em>emphasize</em> enough the <em>significance</em> of Cascading Style Sheets.</b>

Which would render:

I can't emphasize enough the significance of Cascading Style Sheets.

Contextual selectors can be grouped.

selector selector, selector selector { property: value }

Notice the coma ( , ) between the selector groups.

So now if you want all emphasized text within bold and H4 text to be blue, you could do this:

b em, h4 em { color: #0000ff; }

Then in the body of the page you could put:

<h4><em>Contextual</em> Selector Example</h4>
<b>I can't <em>emphasize</em> enough the <em>significance</em> of Cascading Style Sheets.</b>

Which would render:

Contextual Selector Example

I can't emphasize enough the significance of Cascading Style Sheets.

Class And ID

What CSS we can add to elements depends on the compatibility with WebTV. Anything beyond the basics that we will discuss here, is simply a matter of trying them out. Sometimes what doesn't work by applying it to the element, or times when we want to make style changes here and there on our pages, or times when we want to effect several instances of the same type element, we can use a class or id. And perhaps in conjunction with the <div> or <span>.

We can name a class or id anything we want to, as long as it begins with a letter (a - z). After that the name can also have numbers (0 - 9) and hyphens ( - ). They can also include some characters from ISO 10646 and some escaped characters. I keep it simple by starting a class or id with a letter and then use letters and numbers after that. Although classes are not case sensitive, it is a good idea to use lower case, as the future of markup language will require that.

Here's an example of a class:

p.txt1

Notice the dot/period between the element (in this case p) and the class name (in this case txt1).

Then in the body any p element that has txt1 will be affected.

For example:

p.txt1 {
background: #f0f8ff;
color: #00008b;
font-size: 19pt;
font-style: italic;
}

Then in the body:

<p class="txt1"> This is an example of using class to change text. </p>

Which would render:

This is an example of using class to change text.

We can accomplish the same thing by dropping the element (in this case p) from the class:

.txt1

Notice the period/dot ( . ) at the beginning.

Then we can use that class on any element including span or div. This time I'll use span:

<span class="txt1"> This is an example of using class to change text. </span>

This is an example of using class to change text.

Notice the difference between using p and span. With p the background color flows to the right side of the page. With span it's contained where the text is.

With span we can affect a single word or letter with css:

This is an <span class="txt1">example</span> of using class to ch<span class="txt1">a</span>nge text.

This is an example of using class to change text.

We can simplify it even more by using i as the selector:

i {
background: #f0f8ff;
color: #00008b;
font-size: 19pt;
font-style: italic;
}

This is an <i>example</i> of using class to ch<i>a</i>nge text.

This is an example of using class to change text.

Here's an example of id:

#txt2

Notice the number sign ( # ) at the beginning.

An id is pointed toward a specific, one time use. Unlike a class where we can use the same class more than once, an id is for one particular instance. For example:

#txt2 {
color: #d2b48c;
font-size: 23pt;
}

Can be applied to one element only.

<div id="txt2">division content goes here</div>

Now that it's been applied, we can't go ahead and use it on another element.

One example where this really comes into play is with absolute positioning. Where each absolutely positioned element has it's own id (identifier).

Anchor Pseudo-Classes

Link, Vlink and Alink

Here are the selectors for link, vlink and alink:

a:link
a:visited
a:active

Notice the colon ( : ) between the a and link, the a and visited, and the a and active.

Each one of these selectors can have completely different properties and values. They are independent of each other.

Here are examples from this page:

a:link {
color: #8b4513;
font-size: 19pt;
text-decoration: none;
}

a:visited {
color: #2f4f4f;
font-size: 19pt;
text-decoration: none;
}

a:active {
color: #a9a9a9;
font-size: 19pt;
text-decoration: none;
}

As you can see I've kept them very basic, I only changed the color. I could have had all different sizes, alignment, family, style, decoration, and any other properties and values I wanted. An important point to make here is text-decoration: none. PC viewers find it anoyying that links are usually underlined. By using text-decoration: none, the underline will be removed from the links. Most PC viewers will appreciate that consideration.

Putting It All Together

Now I'll take some of the examples and put them together to give you an idea of how it works. I've included some line and paragraph breaks in the examples to make it easier to read.

<html>
<head>
<title>CSS Example</title>
<style type="text/css">
<!--

body {
background: #ffffff;
color: #000000;
}

a:link {
color: #8b4513;
font-size: 19pt;
text-decoration: none;
}

a:visited {
color: #2f4f4f;
font-size: 19pt;
text-decoration: none;
}

a:active {
color: #a9a9a9;
font-size: 19pt;
text-decoration: none;
}

/*page title*/
h1 {
color: #dc143c;
font-size: 27pt;
font-weight: normal;
text-align: center;
}

/*larger and centered text*/
p {
color: #00008b;
font-size: 23pt;
text-align: center;
}

/*contextual example*/
b em, h4 em {
color: #0000ff;
}

/*class example*/
.txt1 {
background: #f0f8ff;
color: #00008b;
font-size: 19pt;
font-style: italic;
}

-->
</style>
</head>
<body>
<h1>Page Title</h1>

The body text is here.

<p>The larger and centered dark blue text is here.</p>

<h4><em>Contextual</em> Selector Example</h4>

<b>I can't <em>emphasize</em> enough the <em>significance</em> of Cascading Style Sheets.</b>

<p>
<span class="txt1">This is an example of using class to change text.</span>
</p>

Visit These Sites !
<br>
<a href="http://www.wtv-zone.com/Cherry-Drops/index-2.html">Cherry-Drops Gifs</a>
<br>
<a href="http://www.gnu-bee.com/index1.html">Midnight Midis</a>
<br>
<a href="http://msvs-magic.com/">MsV's Magic</a>

</body>
</html>

Which would look like this:

Page Title

The body text is here.

The larger and centered dark blue text is here.

Contextual Selector Example

I can't emphasize enough the significance of Cascading Style Sheets.

This is an example of using class to change text.

Visit These Sites !
Cherry-Drops Gifs
Midnight Midis
MsV's Magic

This is a very basic example. Even with the limited compatibility, there's much more we can do with CSS to make our pages more efficient, simpler and W3C compliant.

Be sure to check out the "Go To" links at the top of the page for information on topics not yet covered. And of course, the references provided contain a wealth of information not found here.