|
|
<HEAD> <STYLE TYPE="text/css"> <!-- H1 { color: blue } --> </STYLE> </HEAD><BODY> <H1> A blue header </H1> </BODY> |
A blue header |
With the above definition, all H1 headers on your page will instantly have a blue color. Starting to see the power of CSS?
If you want your header aligned in the center of the document, you can add the 'text-align' property as follows:
H1{ color: blue; text-align: center; }
Classes allow you to define a style whereby this style can then be applied to multiple elements on your page. To create a class, use a custom name with a period in front of it. For example:
<STYLE TYPE="text/css"> <!-- .myIndent { margin-left: 1.0in } --> </STYLE>
Let's apply "myIndent" to both a <H3> and <P> tag on the page:
<H3
CLASS=myIndent>Indented Header</H3> <P CLASS=myIndent>Also this whole paragraph would be indented one inch</P> <P>but this wouldn't be indented</P> |
Indented HeaderAlso this whole paragraph would be indented one inch but this wouldn't be indented |
IDs are similar to classes except they work on a per element basis. The idea behind the ID is to define a certain style for a single specific element. ID is also used extensively by DHTML to reference and manipulate this element. They can not be used by multiple tags on the same page as the above example did.
IDs are defined with a pound sign (#) in front of a custom name.
#item1ID { font: 72pt Courier }
The subsequent HTML tag to reference this ID would be:
<SPAN ID=item1ID>some really large type</SPAN>
Being the tricky guy that I am, I have used a new tag, SPAN, to segue into the next topic.
Two new tags have also been introduced to implement CSS. The tags alone do not have any predefined attributes, and are there for style to be applied to them.
Ok, I think we have the basics out of the way. Let's get down and dirty with CSS now.