0
0
CSSmarkup~20 mins

CSS calc usage - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Calc Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the computed width of the box?
Given the CSS below, what will be the width of the .box element if the parent container is 400px wide?
CSS
.box {
  width: calc(100% - 50px);
}
A50px
B350px
C400px
Dcalc(100% - 50px) (not computed)
Attempts:
2 left
💡 Hint
Remember that 100% means the full width of the parent container.
layout
intermediate
2:00remaining
How does calc affect margin in this example?
If the CSS below is applied, what is the left margin of the .item element when the viewport width is 800px?
CSS
.item {
  margin-left: calc(10vw + 20px);
}
A20px
B80px
C100px
Dcalc(10vw + 20px) (not computed)
Attempts:
2 left
💡 Hint
1vw equals 1% of the viewport width.
🧠 Conceptual
advanced
2:00remaining
What error occurs with this calc usage?
Consider this CSS snippet. What error or problem will it cause in browsers?
CSS
.header {
  height: calc(50% - 20);
}
AHeight becomes 30% automatically
BNo error, height is 50% minus 20px
CRuntime error: Invalid calculation
DSyntaxError: Missing unit after number 20
Attempts:
2 left
💡 Hint
In calc, all numbers must have units unless they are zero.
selector
advanced
2:00remaining
Which option correctly uses calc with CSS variables?
Given the CSS variables below, which option correctly sets the width using calc?
CSS
:root {
  --sidebar-width: 250px;
  --gap: 20px;
}
.container {
  width: /* fill here */;
}
Acalc(var(--sidebar-width) + var(--gap))
Bcalc(--sidebar-width + --gap)
Ccalc(var(--sidebar-width + var(--gap)))
Dcalc(var(--sidebar-width) var(--gap))
Attempts:
2 left
💡 Hint
Use var() to access CSS variables inside calc and separate with operators.
accessibility
expert
2:00remaining
How does using calc improve accessibility in responsive design?

Which statement best explains how calc() helps create accessible layouts?

A<p>It allows combining relative and absolute units to adapt layout sizes, improving readability on different devices.</p>
B<p>It disables zooming to keep layout fixed.</p>
C<p>It automatically increases font size for screen readers.</p>
D<p>It hides content that does not fit the screen.</p>
Attempts:
2 left
💡 Hint
Think about how combining units helps with flexible layouts.