|
The basics, ids, classes, and spansThe previous page explained how style sheets are referenced by the browser. This page expands on that and shows several working examples of style sheets. Starting off with applying a color to a simple header tag, H1. Here is the complete code for the HTML file with a simple 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; } ClassesClasses 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:
IDsIDs 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. SPAN and DIVTwo 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.
|