Site Banner

Caroline's Corner

Home

html/xhtml

User Analysis

Design

Accessibility

CSS

Documentation

JavaScript

Testing

Links to Tips, Tutorials & Tools

PHP

Cascading Style Sheets

CSS gives more control over the appearance of a Web page to the page creator than to the browser designer or the viewer. With CSS, the sources of style definition for a given document element are in this order of precedence:

  1. The STYLE attribute on an individual element tag
  2. The STYLE element that defines a specific style sheet containing style declarations or a LINK element that links to a separate document containing the STYLE element. In a Web page, the STYLE element is placed between the TITLE statement and the BODY statement.
  3. An imported style sheet, using the CSS @import notation to automatically import and merge an external style sheet with the current style sheet
  4. Style attributes specified by the viewer to the browser
  5. The default style sheet assumed by the browser

In general, the Web page creator's style sheet takes precedence, but it's recommended that browsers provide ways for the viewer to override the style attributes in some respects. Since it's likely that different browsers will choose to implement CSS1 somewhat differently, the Web page creator must test the page with different browsers.

Reference: http://searchwebservices.techtarget.com/sDefinition/0,,sid26_gci211749,00.html

Importing Stylesheets

Using CSS @import Notation to link stylesheets to pages is suitable for CSS that you don't want old browsers trying to use . It is similar to the <link href="css/stylesheet.css" rel="stylesheet" type="text/css" /> method but is only supported by browsers of versions 5 and above. Netscape and Internet Explorer 4 will not be able to read the stylesheet you attach this way, and so it is useful to apply things like positioning and CSS layout through this method, as old browsers mangle this code and occasionally crash if you give it to them. The code to import, which is placed in the <head> is:

<style type="text/css" media="all">
@import "style.css";
@import "advanced.css";
</style>

Note: This method is not available specifically to block out stylesheets to old browsers. It just happens that the two version 4 browsers did not support this implementation. This method is meant as a way to add partial stylesheets to your main sheets, so many sources are combined as one.

Implementation Overriding

CSS code can override other existing CSS code depending on how it is implemented. Say you had redefined the <p> tag in an external stylesheet. If you redefine it again in the head section of a document, this definition will be the one that is used, as it is closer to the things that it affects. Adding CSS using the style attribute will override anything else that has been specified elsewhere.

Overriding-wise, the sheet imported last will override the imported ones that come before - i.e. in the example above, 'advanced.css' has more weight than 'style.css' because it is imported below it. Imported stylesheets have the least influence over the final presentation of a page overall, as linked sheets will override them. So we finally have a full cascade order :

  • the style attribute overrides
  • a style block, which overrides
  • a linked stylesheet, which overrides
  • an imported sheet.

Reference: http://www.yourhtmlsource.com/stylesheets/advancedcss.html#IMPORTINGSTYLE

CSS Slideshow

W3Sshools CSS Tutorials

CSS Reference Page

Westciv has free tutorials on CSS

Good CSS examples

Lots of Lists in CSS

Accessibility and CSS

Good Tutorials