Challenge - 5 Problems
Class Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
What color will the text be?
Given the CSS and HTML below, what color will the text inside the
tag appear as in the browser?
CSS
HTML: <p class="highlight">Hello World</p> CSS: .highlight { color: red; } .highlight.special { color: blue; }
Attempts:
2 left
💡 Hint
Look at the class attribute in the HTML and which CSS selector matches it exactly.
✗ Incorrect
The paragraph has only the class 'highlight'. The selector '.highlight' applies red color. The '.highlight.special' selector requires both classes, which the paragraph does not have, so blue does not apply.
❓ layout
intermediate2:00remaining
Which CSS rule centers the box horizontally?
You want to center a
with class 'box' horizontally inside its parent. Which CSS rule using class selectors will do this correctly?
CSS
HTML: <div class="container"> <div class="box">Content</div> </div> CSS: .container { width: 300px; border: 1px solid black; } .box { width: 100px; height: 100px; background: lightblue; }
Attempts:
2 left
💡 Hint
Think about how margin auto works for block elements.
✗ Incorrect
Setting left and right margins to auto on a block element centers it horizontally inside its parent container. 'text-align' affects inline content, 'float: center' is invalid, and 'display: inline-block' alone does not center the box.
🧠 Conceptual
advanced2:00remaining
What does this CSS selector target?
Consider the CSS selector '.menu > .item.active'. Which elements will this selector apply styles to?
Attempts:
2 left
💡 Hint
Look at the '>' symbol and the order of classes.
✗ Incorrect
The '>' means direct child. So '.menu > .item.active' targets elements that have both 'item' and 'active' classes and are direct children of an element with class 'menu'.
❓ accessibility
advanced2:00remaining
How to improve accessibility with class selectors?
You have a button with class 'btn-primary'. Which practice improves accessibility when styling this button using class selectors?
Attempts:
2 left
💡 Hint
Think about users with vision difficulties.
✗ Incorrect
High contrast colors help users with low vision read text easily. Light text on light background or very small fonts reduce readability and accessibility.
📝 Syntax
expert2:00remaining
What error does this CSS code cause?
What error or problem will the following CSS code cause when used in a stylesheet?
.box { color: blue
background: yellow; }
CSS
.box { color: blue background: yellow; }
Attempts:
2 left
💡 Hint
Check punctuation carefully in CSS declarations.
✗ Incorrect
CSS requires each property declaration to end with a semicolon except the last one. Missing semicolon after 'color: blue' causes a syntax error and the whole rule may be ignored.