|
|
Using Cascading Style SheetsCascading Style Sheets (CSS) are lists of font and page preferences that you can save to an external file and then call from within your web page. In browsers that understand them (generally 4.0 and up), they are very valuable for making broad sweeping changes to an entire site by simply changing one file.It should be noted that any colors that you have manually set from within the page will override the style sheet. If you want the style sheet to take precedence over the page, you must use the important tag. To make a Cascading Style Sheet,
The .css identifies the file as a cascasding style sheet. (LOOK OUT! YOUR'E WRITING CODE!)
<STYLE TYPE="text/css"> This is identifying that you are writing a style sheet.
<STYLE TYPE="text/css"> </STYLE>
<STYLE TYPE="text/css"> </STYLE>
<STYLE TYPE="text/css"> <!-- --> </STYLE> This is the shell for every Cascading Style Sheet. You will never have to type another one if you:
Between the <!-- and --> tags, you will be defining style for elements on your web page. The syntax for this is: TAG { property:modifier; property:modifier; property:modifier } You can include as many properties and modifiers as you want. Or, as few properties and modifiers as you want. In the example below, I apply some modifiers to the headings:
Now, all of the level three headings (the H3 tag) will be in blue Lucinda. Our level four headings (the H4 tag) will be in Ariel (or Helvetica or san serif) and will be red and bold:
Many of the existing HTML tags can be affected using a Cascading Style Sheet. Below, I have summarized some of the tags that can be altered and the properties that can be modified.
Text ModifiersAny tag that affects text - that is, all headings, links, etc. can have a number of modifications made:
Controlling Page Background with CSS
To use a background image, use the code:
To set the background color, use the code: BODY { BACKGROUND: color } Substitute the name of the color for color.
Creating your own stylesIn additon to altering existing text syles, you can also create your own for an endless number of variations in your text, all controlled from one place. The syntax for creating your own style is: .stylename { property:modifier; property:modifier; property:modifier } For example, let's say that you want to make sure that all product names appear bold red. You might create a style called "productname": .productname { font-weight: bold; color: red } It is important to note the period (.) used at the beginning of a custom style name. The style will not work unless you use a period at the beginning. To apply the style in your document, you must use the <SPAN> tag in your HTML. For example, to apply the .productname class to the word "Widget", we would use the code: <span class="productname">Widget</span> You can use any of the modifiers listed under Text Modifiers, above.
Getting your HTML document to load your CSSIn the head of your HTML file (anywhere between the <HEAD> tage and the </HEAD> tag), use the code:
|
©2000 Harry Knight Certain elements (software titles, search engine logos, etc.) are copyright and/or trademarks of the respective copyright owners. Use of this material is restricted to educational use and is intended to promote both further understanding of the intellectual property discussed and, in effect, the product itself. |