With stylesheets (CSS, or Cascading Stylesheets) you can separate the structure of a web document from its formatting; your HTML code is cleaner (no <font tags etc.) and the formatting instructions for visual browsers (such as Firefox and IE) are in the style sheet. This makes your pages more accessible to alternative browsers, such as screen-reading software. How do they workWhen you write web pages you use <H1> and <p> tags etc. to structure your document and the browser (Netscape or Internet Explorer) uses its own stylesheet to determine how to display these elements - <H1> is usually displayed in Times New Roman font, large font size etc. One way to alter the formatting of your page is to use <font>
tags and attributes of <p> tags (align etc.) in your HTML
code. However, this leads to messy coding and a lot of work if you
want to change the pages. An alternative is to use your own stylesheets.
The browsers use your style declarations to format the <H1>
and <p> elements, rather than using their own default stylesheets.
You must use closing tags for <p> and <li> etc. or the
stylesheet will not work and you may not see anything on your page! Adding styles to your web pagesYou can use styles in your web documents in one of three different ways:
1. External Stylesheet
2. Embedded stylesheet
3. Inline Style >
Stylesheet syntaxAn external stylesheet is a text file (filename.css) containing a list of all your selectors with their declarations. Types of selector
Using Stylesheets in Dreamweaver 4 & MXFrom the Window menu, choose CSS Styles to open the CSS styles window. you can link to and create external stylesheets, and you can create and edit styles in external stylesheets or in embedded style sheets. If you want to edit and external stylesheet directly, Dreamweaver 4 users will need to open it in Notepad, MX users can edit the style sheet from within Dreamweaver. To apply a style, select the element in the Dreamweaver editing window and click on the desired style in the CSS styles window. Browser compatibility issuesSince IE & Netscape have released versions at differing times with respect to the announcement of the CSS1 and then CSS2 standards, it is hardly surprising that they will interpret your stylesheets differently. IE is more standards compliant, but you will need to test your pages in both browsers to account for undesigned effects! Note how the background colour of a paragraph behaves differently in a simple page that uses an external stylesheet, when viewed in Netscape (v4.7) and in IE (v6.0), in our browser difference example. Rules in conflictInheritance Why cascading? Specificity Accessibility mattersCSS was originally designed to separate structure from formatting, partly with the intention of improving accessibility by allowing different stylesheets for different browsers (text, speech, braille etc.). However, some of the styles make it easier to restrict the ways in which your page can be viewed. For example, when specifying font-size you can use a number of units to set the value. Absolute values (e.g. point size or pixel) prevent the user from changing the text size through their browser, relative values (e.g. ems or %) don't impose this restriction. Although it is tempting to control your display, remember that you are making your pages inaccessible to some users; this now contravenes the University's legal obligation to provide equal access. The key Guidelines and Checkpoints (paraphrased) from the W3C's WAI (Web Accessibility Initiative) are:
Some examples of CSSFirstly, look at the straightforward HTML file with no stylesheet
information in it. You will see it displayed using your browser's
default stylesheet (unless you have changed it, of course): Now look at the same file when it includes a line that refers to
a separate stylesheet file: If you want to use the stylesheets yourself, or to save a copy
to study, please help yourself (right-click to save a copy):
|