CSS Specificity — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the CSS Specificity lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Let the id win
easy10 minMake #one red even though a class rule sets it blue.
- 2
Beat an element rule with a class
easy10 minA class outranks a bare element selector.
- 3
Raise specificity without an id
easy10 minUse a compound selector so the paragraph turns green.
- 4
Win with two classes
easy10 minTwo class selectors outrank one.
- 5
Prefer specificity over !important
medium10 minMake #one green using a more specific selector, not !important.
Find the bug(5)
- 1
Fix the class that cannot beat an id
easy8 minAn id outranks any number of classes.
- 2
Fix the element rule expected to win
easy8 minThe class rule is more specific than the element rule.
- 3
Fix the !important crutch
easy8 minReplace !important with a properly specific selector.
- 4
Fix the selector that never matches
easy8 minThe compound selector targets a class the element does not have.
- 5
Fix the over-specific override
easy8 minA tie should be broken by order, not by adding an id.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace