CSS Selectors
Type Selectors
- Matches element name.
h1 {...}
Universal Selectors
Class Selectors
ID Selectors
- Add the ID attribute to the HTML element
- You define the value
- The value is the selector, starting with a # symbol
- Can only be used once per page.
Descendant Selectors
Creates matching patterns based on the relationship between nested elements
Grouping Selectors
Combining Selectors
Specificity
Specificity determines how browsers decide which CSS rule takes precedence.
- Universal (*)
- Element (p)
- Class / pseudo-class (.example)
- ID (#example)
- Inline Styles
- !important
Specificity Calculator
https://Specificity.keegan.st
Advanced Selectors
Child Combinator (>)
Only matches to direct child element
Sibling Combinators (+, ~)
Adjacent Sibling Combinators (+)
General Sibling Combinator (~)
Pseudo-Class Selectors