Challenge - 5 Problems
CSS Calc Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2: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); }
Attempts:
2 left
💡 Hint
Remember that 100% means the full width of the parent container.
✗ Incorrect
The calc(100% - 50px) means take the full width of the parent (400px) and subtract 50px, resulting in 350px.
❓ layout
intermediate2: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); }
Attempts:
2 left
💡 Hint
1vw equals 1% of the viewport width.
✗ Incorrect
10vw means 10% of 800px, which is 80px. Adding 20px gives 100px total margin-left.
🧠 Conceptual
advanced2: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); }
Attempts:
2 left
💡 Hint
In calc, all numbers must have units unless they are zero.
✗ Incorrect
The value 20 has no unit like px or %. CSS requires units for numbers in calc except zero. This causes a syntax error.
❓ selector
advanced2: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 */;
}Attempts:
2 left
💡 Hint
Use var() to access CSS variables inside calc and separate with operators.
✗ Incorrect
Option A correctly uses var(--sidebar-width) and var(--gap) with a plus sign inside calc. Other options have syntax errors.
❓ accessibility
expert2:00remaining
How does using calc improve accessibility in responsive design?
Which statement best explains how calc() helps create accessible layouts?
Attempts:
2 left
💡 Hint
Think about how combining units helps with flexible layouts.
✗ Incorrect
Using calc() lets designers mix percentages and pixels, so layouts adjust smoothly to screen sizes. This flexibility helps users read and navigate content better on all devices.