The Cascade, Specificity and Inheritance — Concept Check
Questions on The Cascade, Specificity and Inheritance. When two rules apply, one wins. Knowing exactly how that is decided is the difference between debugging CSS and adding !important until it works.
Questions in this quiz
8 questions on The Cascade, Specificity and Inheritance — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices their CSS styles are not applying to a paragraph inside a card component. The styles are defined in a stylesheet with the following rules: `.card p { color: blue; }` and `p { color: red; }`. What is the likely reason the paragraph is not blue?
- AThe `.card p` rule is less specific than `p`.
- BThe `p` rule is defined later in the stylesheet.
- CThe `.card p` rule has a higher specificity.
- DThe browser defaults are overriding the styles.
2.Given the CSS rules `#header .nav-item { color: green; }` and `.nav-item { color: blue; }`, what color will `.nav-item` elements inside `#header` be?
- AGreen, because `.nav-item` is less specific.
- BGreen, because `#header .nav-item` is more specific.
- CBlue, because `#header .nav-item` is less specific.
- DBlue, because `.nav-item` is defined first.
3.A developer uses `!important` in their CSS to override styles. In which scenario is using `!important` considered appropriate?
- ATo quickly fix a bug in their own stylesheet.
- BTo avoid learning about specificity.
- CTo override styles from a third-party library.
- DTo ensure their styles always apply first.
4.Which CSS property will not be inherited by child elements?
- Aline-height
- Bbackground
- Ccolor
- Dfont-family
5.A developer has the following CSS: `.button { color: black; } .button--active { color: red; }`. They notice `.button--active` styles are not applying. What could be the reason?
- A`.button--active` has a lower specificity score.
- B`.button--active` is defined before `.button`.
- C`.button` is more specific than `.button--active`.
- D`.button` and `.button--active` have the same specificity.
6.In a CSS file, the rule `.container .item { color: blue; }` is not applying to `.item` elements inside `.container`. Which of the following could be a reason?
- AThe `.item` class is not applied to the elements.
- BThe rule is defined after a conflicting rule.
- CThe `.container` class is not applied to the parent element.
- DThere is a more specific rule with higher specificity.
7.Which of the following CSS rules has the highest specificity?
- A`#footer .nav-item`
- B`.nav-item`
- C`li::marker`
- D`.nav-item:hover`
8.A developer is using a utility-first CSS framework where every class has a specificity of (0,0,1,0). How does this affect the cascade?
- ASpecificity is calculated as usual.
- BUtility classes cannot be overridden.
- CClasses with more properties win.
- DSpecificity is ignored, and source order decides.