Information Systems | College of Business Administration | University of Missouri - St. Louis |
Ten little known tricks with CSS.Style sheets represent one or more rules that guided how HTML is interpreted. Style rules have two parts: the selector and the declaration. The rules always appear in the "heading" section (between <HEAD> and </HEAD> and before the <BODY ....> section of the page), and must be identified as style rules.
In this example,
The first command simply causes all text that is governed by a "heading tag" to use the font-family of "arial," So, if I eliminate the heading tag use with a </font>,Or, look at the example page that does not have the first line of the style command in it at all.
The second command makes the <h4> tag always appear at 10 point. See an example of a page that uses 22 point instead. he only difference in the pages up until that point is that I substituted the following code in the style sheet.There are a variety of properties that can be affected with CSS. The Web Design Group maintains a summary of these properties and possible values. Among the ones they have documented are:
Consider some of those that might make your pages look different than others. For example, background color. Suppose you want all examples of <H1> to have a particular background. You might use the following code:
Then, every time you use Heading Size, <H1>,you get white font on a purple background. Look at this example. This means all of a certain kind of heading will look the same.Or, for example, "word spacing" which defines the amount of space between words. If you used it on only some items, like words in italics, you can get some interesting effects. Consider this example which includes only this paragraph, but also has the following style sheet commands added to those we have already discussed.
If you look at the example using Netscape 4.x, you probably see no substantial differences. If you look at the example using IE or Netscape 6.0 you will see a big difference. This leads to the point that not every combination works in all browsers. Look here for information about what combinations work in what browsers. Sometimes you want to make changes in blocks of code to emphasize (or de emphasize) them. In this case, you want to use the "SPAN" selector. It allows you to set a particular feature globally and use it as you want. Consider the following code:
This means that any text between the <SPAN> and the </SPAN> tags will be larger, white and on an purple background. Look at the example where we used this definition in the style commands AND applied the <SPAN> and the </SPAN> tags to this paragraph. Please note that we also defined the <SPAN> and the </SPAN> tags on this page, but did not define them in the style commands.
This example is defined using the <DIV> and </DIV> tags similarly to the <SPAN>
tags above. Notice the primary difference is the divider lines.
Another useful concept is that of "classes." Classes allow us to define rules for applying our styles in an easy way. The best example is where we want to have a table with alternating color rows. In our style area (still located in the heading), we define two classes as shown below.
The result would appear as below:
You want more information? Check out W3C's overview of CSS.
|