0
0
CSSmarkup~20 mins

Class selectors in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Class Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2: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; }
AGreen
BBlue
CBlack (default)
DRed
Attempts:
2 left
💡 Hint
Look at the class attribute in the HTML and which CSS selector matches it exactly.
layout
intermediate
2: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; }
A.box { display: inline-block; }
B.box { text-align: center; }
C.box { margin-left: auto; margin-right: auto; }
D.box { float: center; }
Attempts:
2 left
💡 Hint
Think about how margin auto works for block elements.
🧠 Conceptual
advanced
2:00remaining
What does this CSS selector target?
Consider the CSS selector '.menu > .item.active'. Which elements will this selector apply styles to?
AElements with class 'item' and 'active' that are direct children of an element with class 'menu'.
BAny element with class 'active' inside an element with class 'item' inside '.menu'.
CAll elements with class 'menu' that have a child with classes 'item' and 'active'.
DElements with class 'menu' and 'item' and 'active' all at once.
Attempts:
2 left
💡 Hint
Look at the '>' symbol and the order of classes.
accessibility
advanced
2: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?
AUse high contrast colors in '.btn-primary' styles to ensure text is readable.
BUse very light text color on light background in '.btn-primary'.
CUse only background colors without changing text color in '.btn-primary'.
DUse font size smaller than 10px in '.btn-primary' for compact design.
Attempts:
2 left
💡 Hint
Think about users with vision difficulties.
📝 Syntax
expert
2: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; }
ANo error; CSS will apply both color and background correctly.
BSyntax error due to missing semicolon after 'color: blue'.
CRuntime error in browser console.
DThe background color will be ignored but text color applies.
Attempts:
2 left
💡 Hint
Check punctuation carefully in CSS declarations.