Challenge - 5 Problems
Class Attribute Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What color will the text be?
Given the following HTML and CSS, what color will the text inside the <p> tag appear as in the browser?
HTML
<style> .red { color: red; } .blue { color: blue; } </style> <p class="red blue">Hello World!</p>
Attempts:
2 left
💡 Hint
CSS rules applied later or with higher specificity override earlier ones.
✗ Incorrect
When multiple classes are applied, the last declared CSS rule with the same specificity wins. Here, .blue is declared after .red, so the text color is blue.
❓ selector
intermediate2:00remaining
Which CSS selector targets all elements with both classes?
You want to style only elements that have both classes
btn and primary. Which CSS selector should you use?Attempts:
2 left
💡 Hint
No spaces means both classes on the same element.
✗ Incorrect
The selector '.btn.primary' matches elements that have both classes 'btn' and 'primary'. A space means descendant, so '.btn .primary' matches elements with class 'primary' inside elements with class 'btn'.
🧠 Conceptual
advanced2:00remaining
What happens if you use the same class name multiple times in class attribute?
Consider this HTML:
<div class="box box highlight">Content</div>. How does the browser treat the repeated class box?Attempts:
2 left
💡 Hint
Think about how class names are used for styling and scripting.
✗ Incorrect
Class names are treated as a set. Repeating the same class name multiple times has no additional effect; it is as if it appears once.
❓ accessibility
advanced2:00remaining
How to improve accessibility when using class names for styling?
You use class names like
red-text or big-font to style elements. What is a better practice to improve accessibility?Attempts:
2 left
💡 Hint
Think about how assistive technologies understand your page.
✗ Incorrect
Class names should describe the meaning or role of content, not just how it looks, so assistive technologies and developers understand the structure better.
📝 Syntax
expert2:00remaining
What error occurs with this class attribute syntax?
What error will the browser show for this HTML snippet?
<div class=red blue>Text</div>HTML
<div class=red blue>Text</div>
Attempts:
2 left
💡 Hint
Look at how HTML attributes are parsed when quotes are missing.
✗ Incorrect
Without quotes, the browser treats the first word as the attribute value and the second word as a separate attribute. So 'class=red' is valid, 'blue' is an unknown attribute.