
- 3 min read
CSS Specificity — quiz answer sheet, click to expand.
Answer: A way to determine which CSS rule applies when multiple rules match the same element
Explanation: CSS specificity is a set of rules that determines which CSS rule will be applied to an element when multiple rules match it. It is calculated based on the types of selectors used in the rules, such as IDs, classes, and element selectors.
Answer: 1 class selector
Explanation: The specificity score is calculated following this format (ID, class/pseudo-class/attribute, element/pseudo-elements). A score of 0-1-0 indicates that there is one class selector and no ids or element selectors.
Answer: .box.box
Explanation: Repeating the same class name increases the specificity of the class selector.
Answer: 1-1-0
Explanation: only what's inside :not() counts.
Answer: :is(.cls)
Explanation: The universal selector `*` and `:where()` have 0 specificity.
Answer: false
Explanation: ID selectors outrank any number of class or element selectors.
Answer: false
Explanation: The specificity of #myId is 1-0-0 while [id="myId"] has 0-1-0.
Answer: 1-0-0
Explanation: :is() takes the specificity of its most specific inner selector, which is #id (1,0,0).
Answer: 0-2-2
Explanation: .box and :hover are 2 class-like. div and ::before are 2 element-like.
Answer: true
Explanation: Inline styles (style="...") are not part of specificity scoring itself, but they are evaluated earlier in the cascade and override any styles from selectors unless overridden by !important.
Answer: 0-0-0
Explanation: :where() always has zero specificity regardless of what's inside.
Answer: p.btn { color: blue !important; }
Explanation: !important beats specificity unless both have it. Then specificity matters.
Answer: true
Explanation: .btn => 0-1-0, .btn.btn => 0-2-0. Each class adds to the count, same with ids.
Answer: components (last declared)
Explanation: In @layer, later layers have higher priority regardless of specificity. The order of declaration determines precedence: base < theme < components.
Answer: red (from layer)
Explanation: When the !important flag is used in both layers and unlayerd declaration, the priority is reversed and earlier layers has more priority than unlayered rules.
- 3 min read
- 4 min read
- 3 min read