Challenge - 5 Problems
CSS Cascade Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding CSS Cascade Priority
Which CSS rule will apply to the paragraph below if these styles are all present?
HTML:
p { color: blue; }.highlight { color: red; }#main { color: green; }HTML:
<p id="main" class="highlight">Hello</p>Attempts:
2 left
💡 Hint
Remember that IDs have higher priority than classes and element selectors in CSS cascade.
✗ Incorrect
CSS cascade decides which style applies when multiple rules target the same element. ID selectors (#main) have higher priority than class selectors (.highlight) and element selectors (p). So, the color green from #main wins.
📝 Syntax
intermediate2:00remaining
Which CSS rule overrides others due to !important?
Given these CSS rules:
What color will a <div class="alert"> show?
div { color: blue !important; }.alert { color: red; }What color will a <div class="alert"> show?
Attempts:
2 left
💡 Hint
The !important keyword gives a rule the highest priority.
✗ Incorrect
The !important declaration makes the blue color rule override the red color from the class selector, even though classes normally have higher specificity than elements.
❓ selector
advanced2:00remaining
Which selector has the highest specificity?
Consider these selectors:
A)
B)
C)
D)
Which selector has the highest specificity according to CSS cascade rules?
A)
ul li a:hoverB)
#nav .menu aC)
.header .nav a.activeD)
body.home ul li aWhich selector has the highest specificity according to CSS cascade rules?
Attempts:
2 left
💡 Hint
ID selectors count more than classes and elements in specificity.
✗ Incorrect
Selector B has an ID (#nav), which gives it higher specificity than selectors with only classes and elements.
❓ layout
advanced2:00remaining
How does CSS cascade affect conflicting layout styles?
If two CSS rules set different display values for the same element:
And the HTML is:
What will be the display style of the div?
.box { display: flex; }#container { display: grid; }And the HTML is:
<div id="container" class="box">Content</div>What will be the display style of the div?
Attempts:
2 left
💡 Hint
ID selectors have higher specificity than class selectors.
✗ Incorrect
The ID selector (#container) has higher specificity than the class selector (.box), so display: grid applies.
❓ accessibility
expert3:00remaining
How does CSS cascade impact accessibility when styles conflict?
You have these CSS rules:
HTML:
What color will the button text be, and why is this important for accessibility?
button { color: black; }.disabled { color: gray !important; }#submitBtn { color: white; }HTML:
<button id="submitBtn" class="disabled">Submit</button>What color will the button text be, and why is this important for accessibility?
Attempts:
2 left
💡 Hint
The !important keyword overrides normal specificity rules.
✗ Incorrect
The .disabled class uses !important, which overrides the ID selector color. This ensures the button looks disabled visually, which is important for users to understand its state.