Selectors, Specificity, and the Cascade

Book description

Exactly how does the "cascade" in Cascading Style Sheets work? This concise guide demonstrates the power and simplicity of CSS selectors for applying style rules to different web page elements. You’ll learn how your page’s presentation depends on a multitude of style rules and the complex ways they function—and sometimes collide—within the document’s structure. This guide is an excerpt from the upcoming fourth edition of CSS: The Definitive Guide.

Table of contents

  1. Selectors, Specificity, and the Cascade
  2. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
  3. 1. Selectors
    1. Basic Style Rules
      1. Element Selectors
      2. Declarations and Keywords
    2. Grouping
      1. Grouping Selectors
        1. The universal selector
      2. Grouping Declarations
      3. Grouping Everything
    3. Class and ID Selectors
      1. Class Selectors
      2. Multiple Classes
      3. ID Selectors
      4. Deciding Between Class and ID
    4. Attribute Selectors
      1. Simple Attribute Selectors
      2. Selection Based on Exact Attribute Value
      3. Selection Based on Partial Attribute Values
        1. Matching one word in a space-separated list
        2. Matching a substring within an attribute value
        3. Matching a substring at the beginning of an attribute value
        4. Matching a substring at the end of an attribute value
      4. A Particular Attribute Selection Type
    5. Using Document Structure
      1. Understanding the Parent-Child Relationship
      2. Descendant Selectors
      3. Selecting Children
      4. Selecting Adjacent Sibling Elements
      5. Selecting Following Siblings
    6. Pseudo-Class Selectors
      1. Combining Pseudo-Classes
      2. Structural Pseudo-Classes
        1. Selecting the root element
        2. Selecting empty elements
        3. Selecting unique children
        4. Selecting first and last children
        5. Selecting first and last of a type
        6. Selecting every nth child
        7. Selecting every nth of a type
      3. Dynamic Pseudo-Classes
        1. Hyperlink pseudo-classes
        2. User action pseudo-classes
        3. Real-world issues with dynamic styling
      4. UI State Pseudo-Classes
        1. Enabled and disabled UI elements
        2. Check states
      5. The :target Pseudo-Class
      6. The :lang Pseudo-Class
      7. The Negation Pseudo-Class
    7. Pseudo-Element Selectors
      1. Styling the First Letter
      2. Styling the First Line
      3. Restrictions on ::first-letter and ::first-line
      4. Styling (Or Creating) Content Before and After Elements
    8. Summary
  4. 2. Specificity and the Cascade
    1. Specificity
      1. Declarations and Specificity
      2. Universal Selector Specificity
      3. ID and Attribute Selector Specificity
      4. Inline Style Specificity
      5. Importance
    2. Inheritance
    3. The Cascade
      1. Sorting by Weight and Origin
      2. Sorting by Specificity
      3. Sorting by Order
      4. Non-CSS Presentational Hints
    4. Summary
  5. About the Author
  6. Copyright

Product information

  • Title: Selectors, Specificity, and the Cascade
  • Author(s):
  • Release date: October 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449342494