| Copyright 2004, Scott-Jones Publishing. All rights reserved. You may print this tutorial for personal use only, and you may not redistribute it to any other party. |
|
A Cascading Style Sheet (CSS) is collection of document styles recognized by HTML. Most Web sites use CSS files to standardize the appearance of related Web pages. This Web site uses one, for example, that defines the H1 style as Red text, using the Times New Roman font. We use it as the title on each page. Each Visual Basic .NET project has a Cascading Style Sheet file named Styles.css. You can edit the styles in this file by double-clicking the filename in the Solution Explorer window. Here, for example, are two styles defined in the file, Body and H1: /* Default CSS Stylesheet for a new Web Application project */
H1
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 2em;
font-weight: 700;
font-style: normal;
text-decoration: none;
word-spacing: normal;
letter-spacing: normal;
text-transform: none;
}
The BODY style is the default style for all controls and text on a Web form. The H1 style is a Heading level 1 style, perfect for Web form titles. Here's part of the Picnic program's Web form, showing the two styles:
Attaching a Style Sheet to a Web FormBefore working with styles in a particular Web form, you must add a style link to the form:
<LINK href="Styles.css" type="text/css" rel="stylesheet"> We could have added this entry directly to the HTML rather than using the Document Styles window. It is possible to create links to more than one CSS file, and it is also possible to link to a CSS file located anywhere on your machine or network. You can also use a single CSS file to generate styles for an entire set of Web applications. Modifying Standard HTML StylesYou can modify standard HTML styles by editing their properties in the Styles.css file. Suppose we want to change the H1 style to Times Roman font, in Red: H1
{
When we save Styles.css, none of the style attributes on the Web form appear to have changed. You must select Refresh from the View menu to see style changes. Here's the output when the sample program runs, showing the new Heading line:
Using the Style Builder WindowAnother way to edit a style in Styles.css is to right-click anywhere inside the style definition and select Build Style. The Style Builder window appears:
As you modify the various style attributes, the builder displays a text sample. For practice, let's select the Background panel and choose an Aqua background for style H1. We will select the Text panel and center the text horizontally. We then select the Edges panel and specify thin black solid lines around all edges:
The dialog's choices have occasional limitations. For example, we cannot select border lines on just the top and bottom. But we can directly edit the code produced by the dialog: H1 If we delete the first two entries (border-right and border-left), the resulting header is the following:
Defining Custom Styles
|