www.Expression-Web-3.com


CSS Tutorials

 

Quick Start Checklist

 

Video Tutorials

CSS & HTML Tutorials

 

Training DVDs & Products

DVD Sets For Beginners

 

 

 

 


Expression Web 3 ~ Rules of the Cascade in CSS

Previous

How The Cascade Works

 

3 Sources of Style Sheets

According to the W3C CSS 2.1 Specifications, Styles originate from:

1.  Author Style Sheets

2.  Web Browser Style Sheets

3.  User Style Sheets

 

focus

  Most of our attention will be focused on Author Style Sheets which includes how Internal, External, and Inline styles interact with each other. 

But you also need to be aware of the other 2 sources so that you understand the Big Picture.

 

Overview

Author Style Sheets:  These are the Style Sheets that you and I create for our web pages.  We are in fact CSS Authors. 

Web Browser Style Sheets:  Each Web Browser (user agent) applies a default Style Sheet to our web pages. 

User Style Sheets:  This has more to do with providing the user with some control over their browsing experiences.  For instance, users can change the font-size in the browser or they can completely disable all CSS Styles. 

 

Should conflict among these 3 sources of Styles occur, the CSS Cascade will resolve the conflict and determine which Style Rule wins.

In general:

 Author Styles take precedence over the Web Browser and User Style Sheets.

And User Styles take precedence over the Web Browser Style Sheets.

 

 

 

 

More About Author Style Sheets

In General:

 

1.  The Style Rule that is Closest to the Element being styled is the Style that will be applied.

This means the 3 Types of CSS will be applied in the following order should there be conflict among styles:

  • 1.  Inline Styles
  • 2.  Internal or Embedded Styles
  • 3.  External Styles

The reason the Inline Style beats the other types of styles is because it is closest to the HTML Element being styled.  Look at the illustration below.

example cascade

The Inline Style is embedded directly within the HTML it is styling.

As mentioned earlier, understanding this one Rule will take you a long way.   Specifically, you can now change a Style for one web page without causing all web pages to be effected.  Simply use an Internal or Inline Style for the page in which you want to make a change from the External style Sheet.

 


2.  The More Specific the Style, the More Likely the Style Will be Applied

Example:  #header h1 is more specific than h1, therefore, #header h1 will win.

 


3.  !important will override all other styles.

If we add the !important statement to the end of a style declaration, it tells the browser to apply this style no matter what was specified elsewhere.

 


4.  The last style specified will take precedence. (therefore, the order in which styles were added will sometimes influence which style wins).