|
Cascading style sheets (CSS) enable you to develop web sites that share a common
look-and-feel (fonts, headings, colors, backgrounds, etc.). CSS
essentially allows you to define how an HTML tag works--in other words, how it
will format content.
CSS...
 | Is a declarative language that is used to enhance the HTML
language. |
 | Is intended to be user friendly; it was purposely designed to be
very readable and writable. |
 | Is lifted from the desktop publishing terminology. |
 | Requires a minimal coding to create sophisticated web pages that have a
common theme in appearance. |
History of CSS
 | The World Wide
Web Consortium (W3C) published a set of standards in December 1996
referred to as the "Cascading Style Sheets, Level 1" standards. |
 | Followed in December 1998 by the "Cascading Style Sheets, Level 2"
standards. |
 | Level 2 was a major revision that almost doubled the size of the CSS
language by adding 42 new properties commonly referred to as CSS2. |
Using CSS...
 | There are three basic types of style sheets:
- Inline - via
the style attribute; tags are modified on a case-by-case basis
throughout a document. e.g., <h1 style="color: blue;
font-style: italic">Text </h1>
- Document-level -
styles are defined by a <style> tag in the head.
- External -
link tag is used to identify a separate file with style information.
Click to view the external sheet.
|
 | Style syntax:
 | 3 parts of a style "rule" -
- tag selector (e.g., H1, P)
- curly brace {}
- semi-colon
separated list of one or more style property:value
declarations (e.g., align:center)
|
 |
They are not case sensitive. |
 | e.g., tag-selector {prop1: value ; prop2:
value1 value2 value3; ...} |
 | Multiple tag selectors can be used. e.g., H1,
H2, H3 {text-align: center} |
|
 | Style classes -
 | Regular - based on
primary document objects, e.g., H1, H2, P , specific tags are
identified, e.g., P.abstract {font-style: italic} ....
<p class=abstract> |
 | Generic - create a generic class that can be used
anywhere., e.g. .italic {font-style:
italic} .... <p class=italic> |
|
Example of styles - note the tag name, curly brackets, property, and
value:
H1 {
margin-left: 15;
font-family: Arial, Helvetica;
font-size: 24pt;
color: "red";
}
p {
font-family: Arial, Helvetica;
font-weight: normal;
font-size: 12pt;
color: "black";
}(NOTE: the following must be applied with a DIV tag)
.demo1 {
COLOR: blue;
font-weight: bold;
}
|
 | Style properties - properties that can be used
control how the browser presents content. Uses property values (5
types): keywords, length values, percentage values, URLs, and colors. |
 | Span tags are useful for
changing styles within a particular part of a document. |
End-User issues:
 | Great for creating consistent, great looking
multi-page documents. |
 | Special needs and layouts can be defined and
enforced. |
Developer issues:
 | It is difficult to keep track of all the possible
combinations. Keep a good reference handy. |
 | WYSIWYG editors are getting better at doing style
sheets. |
 | Be aware of differences in how IE and Netscape handle
styles. |
 | Test across browsers. |
CSS Style Attributes
The following is a sampling of attributes (not all of them - for more see the
summary)...
Fonts
 | family (e.g., font-family:Arial) |
 | size, font-size: 24 |
 | style, font-style: italic |
 | weight, font-weight: bold |
 | text decoration, text-decoration: underline |
 | color, color: red ... color:#040588 ...
color:rgb(255,255,255) |
Backgrounds
 | color, backgroud-color:white |
 | image, background-image:url(file) |
Text
 | word spacing, word-spacing: 10pt |
 | letter spacing, letter-spacing: 3pt |
 | alignment, text-align: justify |
Technical Resources on StyleSheets
Examples
The following examples illustrate a variety of techniques. Use the view
source function of your browser to see the HTML and how they work.
|