Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a CSS variable inside the :root selector.
CSS
:root {
--main-color: [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name as the value instead of a color.
Forgetting the '#' in the color code.
Using
var(--main-color) when defining the variable.✗ Incorrect
The correct way to define a CSS variable is to assign a value like a color code. Here,
#3498db is a valid color value.2fill in blank
mediumComplete the code to use the CSS variable --main-color inside the body selector.
CSS
body {
background-color: [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without
var().Using incorrect syntax like
color(--main-color).Forgetting the double dashes in the variable name.
✗ Incorrect
To use a CSS variable, you must wrap its name with
var(). So var(--main-color) correctly accesses the variable.3fill in blank
hardFix the error in the code to correctly override the CSS variable --main-color inside the .button class.
CSS
.button {
[1]: #e74c3c;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
var(--main-color) as a property name.Using the variable name without dashes.
Using unrelated property names like
color.✗ Incorrect
To override a CSS variable, you must use its full name with double dashes, like
--main-color, not just the name or var().4fill in blank
hardFill both blanks to define a CSS variable --text-size inside :root and use it in the p selector.
CSS
:root {
[1]: 1.2rem;
}
p {
font-size: [2];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without dashes when defining.
Using the variable name without
var() when using it.Mixing variable names like
--main-color instead of --text-size.✗ Incorrect
Define the variable with its name starting with double dashes, then use it with
var() where needed.5fill in blank
hardFill all three blanks to define a CSS variable --padding inside :root, override it inside .container, and use it in the div selector.
CSS
:root {
[1]: 1rem;
}
.container {
[2]: 2rem;
}
div {
padding: [3];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in different places.
Using
var() when defining or overriding variables.Using property names like
padding instead of variable names when defining.✗ Incorrect
Define the variable with
--padding in :root, override it with the same name in .container, and use it with var(--padding) in div.