O'Reilly logo

ASP.NET 4 24-Hour Trainer by Toi B. Wright

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Adding Style to an HTML Page

In this lesson you learn how to use cascading style sheets (CSS) to add style to an HTML page. As I said in Lesson 1, HTML defines the structure of a page, while cascading style sheets define the styles on a page. They can be used to define colors, fonts, and background images and they can be used for page layout. There are over 90 properties that you can use to style your HTML.

CSS RULES

A cascading style sheet is made-up of a collection of CSS rules. This is the CSS rule to modify the colors used by the <h1> tag:

h1 {color:White; background-color:Silver}

This CSS rule sets the text color of all of your <h1> tags to white and their background color to silver, as shown in Figure 3-1.

A CSS rule consists of a selector and one or more declarations. Each declaration is made up of a property and a value, as shown in Figure 3-2.

FIGURE 3-1

Figure 3.1. FIGURE 3-1

FIGURE 3-2

Figure 3.2. FIGURE 3-2

As you can see in Figure 3-2 each declaration is separated by a semicolon. Another way to write this CSS rule is to type each declaration on its own line:

h1
{
    color: White;
background-color: Silver;
}

In the preceding example, all of the <h1> tags on the entire page will be displayed using the new H1 style. If you do not want your style to be applied to every instance of a particular HTML ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required