5. Styles
Cascading Style Sheets (CSS) is an extension to HTML used to apply a unique style (look) to Web pages. One method of using CSS is to create an external style sheet: a separate file that contains a set of style rules (for margins, colors, fonts, etc.) . These rules can then be applied to several pages, giving the Web site a unified look.
To link a page to a style sheet, place the following code in the head section of the page, replacing "filename" with the name of your style sheet file:
<link href="filename.css" rel="stylesheet" media="screen">
A style sheet is simply a list of style rules saved in text-only format with file name extension .css. A rule consists of a selector and a declaration. A selector identifies the HTML content to be styled. A declaration describes the styles to be applied. The following example applies the color green to level 1 headings:
h1 { color: green }
The selector is h1 and the declaration, contained inside the curly braces, consists of a property and value separated with a colon. A declaration can have multiple property-value pairs separated by semicolons, as in the example below.
Following is an example of a simple style sheet that changes the page margins, colors and fonts. You may copy it and modify or expand it to create your own set of styles (use the Web Color Picker to find hexadecimal values of other colors).
body { background: #ffffcc; margin-left: 7%; margin-right: 7%; }
h1, h2, h3 { color: #990000; text-align: center; }
p { font-family: verdana, sans-serif; font-size: 1em; }
To learn more about CSS, read the CSS Overview and consult with me during class.
To develop more Web-design skills, consider enrolling in ENGL 302 Hypertext Writing
(see sample syllabus). The course will be offered next in the spring semester of 2010.
|