little attention to the specifics of how particular items appeared in the browser.
HTML left it to the individual browsers to work out these intricacies, and tailor
the output to the limitations and strengths of users’ machines. While we can
change font styles, sizes, colors, and so on using HTML tags, this practice can
lead to verbose code and pages that are very hard to restyle at a later date.
CSS gives web developers the power to create one set of styles in a single location,
and to apply those styles to all of the pages in our web site. All the pages to which
the style sheet is applied will display the same fonts, colors, and sizes, giving the
site a consistent feel. Regardless of whether our site contains three pages or 300,
when we alter the styles in the style sheet, our changes are immediately applied
to all pages that use the style sheet.
Look out for Themes and Skins
ASP.NET 2.0 provides extra value and power to those building reusable
visual elements through its offerings of themes and skins. You’ll learn more
about these features in Chapter 5.
Types of Styles and Style Sheets
There are three different ways in which we can associate styles to the elements
of a particular web page:
using an external style sheet
By placing your style rules in an external style sheet, you can link this one
file to any web pages on which you want those styles to be used. This makes
updating a web site’s overall look a cakewalk.
To reference an external style sheet from a web form, insert the following
markup inside the head element:
<link rel="stylesheet" type="text/css" href="file.css" />
In the above example, file.css would be a text file containing CSS rules,
much like the example shown below:
a
{
background: #ff9;
color: #00f;
text-decoration: underline;
}
136
Chapter 4: Constructing ASP.NET Web Pages