IS 337: Website Administration

Lecture for September 26: CSS: Cascade, Specificity, Inheritance

+
-

Topics

The Cascade, Specificity, and Inheritance

  • The Cascade toggle
    • The cascade is the accumulation of selector patterns to apply properties to elements.
    • Question: If two or more selectors find the same element, who wins? toggle
      • Step 1: Find all declarations for a particular element.
      • Step 2: Sort the declarations according to importance and origins.
      • Step 3: Sort the ties by selector specificity.
      • Step 4: Sort the ties by declaration order—last one wins!
  • Step 2: Origins and importance toggle
    • Origins: user agent style sheets, author style sheets, user style sheets
    • Origins and importance (important!): toggle
      • user agent declarations
      • normal declarations in user style sheets
      • normal declarations in author style sheets
      • important declarations in author style sheets
      • important declarations in user style sheets
  • Step 4: Declaration order toggle
    • Same declaration block, same style sheet, another style sheet
    • Order of <link> elements matters!
    • No preference over <style> or <link>!
  • Step 3: Specificity toggle
  • Inheritance toggle
    • What if a property for an element is not explicitly defined?
    • Inheritance: children inherit some properties of their parents in the DOM. toggle

Readings and Resources

Quick Written Assignment for Next Time

Calculate the specificities of these selectors:

* {color: red;}
li  {color: maroon;}
ul li {color: green;}
h1 + *[reL=up] {color: purple;}
ul ol li.olive {color: olive;}
li.olive.level {color: olive; font-weight: bold;}
#x34y {color: lime;}

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.