0
0
CSSmarkup~20 mins

Viewport units in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Viewport Units Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding viewport width (vw) unit
If the browser window width is 1000px, what will be the computed width of a box styled with width: 10vw;?
A1000px
B10px
C100px
D10,000px
Attempts:
2 left
💡 Hint
Remember that 1vw equals 1% of the viewport width.
📝 Syntax
intermediate
1:30remaining
Which CSS rule correctly sets height to 50% of viewport height?
Select the CSS rule that sets an element's height to half the viewport height.
Aheight: 50vh;
Bheight: 50vw;
Cheight: 50%;
Dheight: 50pxvh;
Attempts:
2 left
💡 Hint
vh means viewport height, vw means viewport width.
rendering
advanced
2:00remaining
What is the visible height of the box on a 800px tall viewport?
Given this CSS, what is the visible height of the <div> box?

div {
  height: 50vh;
  max-height: 300px;
}
CSS
<div>Box</div>
A50px
B300px
C400px
D800px
Attempts:
2 left
💡 Hint
Check which is smaller: 50vh or max-height.
selector
advanced
2:00remaining
Which CSS selector targets elements with width less than 50vw?
Which CSS media query correctly applies styles only when viewport width is less than 50vw?
A@media (max-width: 50vw) { /* styles */ }
B@media (max-width: 50px) { /* styles */ }
C@media (max-width: 50vh) { /* styles */ }
D@media (max-width: 50%) { /* styles */ }
Attempts:
2 left
💡 Hint
Media queries accept viewport units like vw and vh.
accessibility
expert
2:30remaining
How to ensure text remains readable on small viewports using viewport units?
You want text size to scale with viewport width but never become smaller than 1rem for readability. Which CSS rule achieves this?
Afont-size: clamp(2vw, 1rem, 5vw);
Bfont-size: min(1rem, 2vw);
Cfont-size: 2vw;
Dfont-size: max(1rem, 2vw);
Attempts:
2 left
💡 Hint
Use CSS functions to set minimum font size.