Challenge - 5 Problems
Specificity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
Which CSS rule will apply the red color to the paragraph?
Given the following HTML and CSS, which CSS selector will make the paragraph text red?
CSS
HTML: <p class="text">Hello World</p> CSS: .text { color: blue; } #main .text { color: green; } .text.highlight { color: red; }
Attempts:
2 left
💡 Hint
Think about which selector has the highest specificity and matches the element's classes.
✗ Incorrect
The paragraph matches '.text' (specificity 0,1,0) for blue. '#main .text' (1,1,0) requires #main ancestor (absent). '.text.highlight' (0,2,0) requires 'highlight' class (absent). '.text { color: red; }' has the same specificity as the blue rule but comes later, so it overrides it.
🧠 Conceptual
intermediate1:30remaining
What is the specificity value of the selector
#nav ul li.active a?Calculate the specificity of the CSS selector
- a = number of ID selectors
- b = number of class, attribute, and pseudo-class selectors
- c = number of element and pseudo-element selectors
#nav ul li.active a. Use the format (a,b,c) where:- a = number of ID selectors
- b = number of class, attribute, and pseudo-class selectors
- c = number of element and pseudo-element selectors
Attempts:
2 left
💡 Hint
Count each type of selector carefully: IDs, classes, and elements.
✗ Incorrect
The selector has 1 ID (#nav), 1 class (.active), and 4 elements (ul, li, a). So specificity is (1,2,4) if counting .active and any other class or pseudo-class, but here only one class. Actually, the correct count is 1 ID, 1 class, 4 elements, so (1,1,4).
❓ rendering
advanced2:00remaining
Which color will the button have when rendered?
Consider the following CSS and HTML. What color will the button text be when viewed in a browser?
CSS
HTML: <button class="btn primary">Click me</button> CSS: button { color: black; } .btn { color: blue !important; } .primary { color: red; }
Attempts:
2 left
💡 Hint
Remember that !important overrides normal specificity rules.
✗ Incorrect
The '.btn' class has 'color: blue !important', which overrides other color rules even if they have higher specificity. So the button text will be blue.
❓ accessibility
advanced1:30remaining
Which CSS selector is best to style focus state for accessibility?
You want to improve keyboard navigation by styling the focus state of links. Which selector correctly targets links when they receive keyboard focus?
Attempts:
2 left
💡 Hint
Focus styles should appear only when users navigate with keyboard, not mouse.
✗ Incorrect
The ':focus-visible' pseudo-class applies styles only when the element receives focus via keyboard or other non-mouse input, improving accessibility without distracting mouse users.
📝 Syntax
expert2:00remaining
What error does this CSS snippet cause?
Examine the CSS code below. What kind of error or issue will it cause in the browser?
CSS
div > .item { color: green; } div > .item { color: blue !important } div > .item { color: red; }
Attempts:
2 left
💡 Hint
Check punctuation carefully in CSS declarations.
✗ Incorrect
There is no syntax error (trailing semicolon optional). All rules target the same elements with same specificity. The !important in the second rule gives it highest priority, ignoring the normal declarations before and after.