davesite.com / webstation / css

Cascading Style Sheets: An Interactive Tutorial for Beginners

Cascading Style Sheets: an Interactive Tutorial

All About Selectors

part 2

advertisement

advertisement
#1 Web Hosting Plan! Free Software & Tools!
1000GB space, 1000GB bandwidth, just $6.95!

Why stop at the p tag? Indenting is kind of useful all around. You can make up an element-less selector name and just forgo the element. All you place is a period . and then your class name. Here's a generic example for indent:

.indent { text-indent: 3em; }

Now, we can use that class for all sorts of things. Here's a paragraph and a H1 both using the element-less .indent selector.

<p class="indent"> This is a paragraph with indent. </p>

This is a paragraph with indent.

<h1 class="indent">This div has an indent</h1>.

This h1 has an indent.

Imagine a selector .g, defined as { color: green; }. Every time you use class="g" in an element the text color would be shown in green.

ID selectors are used for special formatting of only a few elements. ID selectors use a # instead of a .. Imagine 3 paragraphs, we'll call them par1, par2, par3. We'll make one red, one orange, and one blue.

We could use these styles:

p#par1 { color: red; }
p#par2 { color: orange; }
p#par3 { color: blue; }

<p id="par1">I'm in red</p>
<p id="par2">I'm in orange</p>
<p id="par3">I'm in blue</p>

ID Selectors can also be element-less:

#par1 { color: red; }

...would apply to all tags that specify id="par1".

advertisement

WIN A NEW CAR! Yahoo! Web Hosting

< Ch. 3 part 1 > Ch. 3 part 3





Learn about the #1 Ranked Web Host. 100 GB Space.
Up to 7 Web Sites. Free Domain & Setup. Click Here.

Copyright © 2002 Dave Kristula. All Rights Reserved.

davesite.com