0
0
CSSmarkup~20 mins

What is CSS cascade - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Cascade Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding CSS Cascade Priority
Which CSS rule will apply to the paragraph below if these styles are all present?

p { color: blue; }
.highlight { color: red; }
#main { color: green; }

HTML:
<p id="main" class="highlight">Hello</p>
AThe paragraph text will be black (default).
BThe paragraph text will be red.
CThe paragraph text will be green.
DThe paragraph text will be blue.
Attempts:
2 left
💡 Hint
Remember that IDs have higher priority than classes and element selectors in CSS cascade.
📝 Syntax
intermediate
2:00remaining
Which CSS rule overrides others due to !important?
Given these CSS rules:

div { color: blue !important; }
.alert { color: red; }

What color will a <div class="alert"> show?
ARed, because class selectors override element selectors.
BIt will cause a syntax error.
CBlack, because no color applies.
DBlue, because !important overrides normal declarations.
Attempts:
2 left
💡 Hint
The !important keyword gives a rule the highest priority.
selector
advanced
2:00remaining
Which selector has the highest specificity?
Consider these selectors:

A) ul li a:hover
B) #nav .menu a
C) .header .nav a.active
D) body.home ul li a

Which selector has the highest specificity according to CSS cascade rules?
Aul li a:hover
B#nav .menu a
C.header .nav a.active
Dbody.home ul li a
Attempts:
2 left
💡 Hint
ID selectors count more than classes and elements in specificity.
layout
advanced
2:00remaining
How does CSS cascade affect conflicting layout styles?
If two CSS rules set different display values for the same element:

.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?
AThe div will use display: grid.
BThe div will use display: flex.
CThe div will have no display style and default to block.
DThe div will cause a layout error.
Attempts:
2 left
💡 Hint
ID selectors have higher specificity than class selectors.
accessibility
expert
3:00remaining
How does CSS cascade impact accessibility when styles conflict?
You have these CSS rules:

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?
AGray, because !important overrides ID selectors.
BWhite, because ID selectors override classes even with !important.
CBlack, because element selectors have priority.
DThe button will be invisible due to conflicting colors.
Attempts:
2 left
💡 Hint
The !important keyword overrides normal specificity rules.