📖 Scenario: You are designing a simple webpage with colored boxes. You want to learn how to make colors more vivid or more muted using Sass color functions.
🎯 Goal: Create a Sass stylesheet that defines a base color and then uses saturate() and desaturate() functions to create two new colors. Apply these colors to three boxes in HTML to see the effect visually.
📋 What You'll Learn
Define a base color variable in Sass
Create a saturated color by increasing saturation of the base color
Create a desaturated color by decreasing saturation of the base color
Use semantic HTML with three section elements for the colored boxes
Apply the colors to the boxes using CSS classes
Include responsive design so boxes stack on small screens
Use accessible color contrast for text inside boxes
💡 Why This Matters
🌍 Real World
Designers and developers often need to adjust colors dynamically to create visually appealing and accessible websites. Using Sass functions like saturate and desaturate helps maintain consistent color schemes.
💼 Career
Understanding Sass color functions and responsive design is essential for front-end developers and UI designers to build modern, accessible, and maintainable web interfaces.
Progress0 / 4 steps
1
Set up base color variable in Sass
Create a Sass variable called $base-color and set it to #3498db (a blue shade).
SASS
Hint
Use the syntax $variable-name: value; to create a Sass variable.
2
Create saturated and desaturated color variables
Create two new Sass variables: $more-saturated by saturating $base-color by 30%, and $less-saturated by desaturating $base-color by 30%. Use the saturate() and desaturate() functions.
SASS
Hint
Use saturate($color, 30%) and desaturate($color, 30%) to adjust saturation.
3
Write CSS classes to apply the colors
Write three CSS classes: .box-base with background $base-color, .box-saturated with background $more-saturated, and .box-desaturated with background $less-saturated. Set text color to white and add padding and margin for visibility.
SASS
Hint
Use background-color: $variable; inside each class and add color: white; for text.
4
Add HTML structure and responsive layout
Write HTML with three section elements with classes box-base, box-saturated, and box-desaturated. Each box should have text describing the color. Add a container main with a CSS flex layout that stacks boxes vertically on narrow screens and horizontally on wider screens.
SASS
Hint
Use semantic section tags with the correct classes and a main container with flexbox and a media query for responsiveness.
Practice
(1/5)
1. What does the saturate() function do to a color in Sass?
easy
A. Makes the color darker
B. Makes the color more vivid and bright
C. Makes the color lighter
D. Makes the color more transparent
Solution
Step 1: Understand the purpose of saturate()
The saturate() function increases the intensity of the color's saturation, making it look more vivid.
Step 2: Compare with other effects
Unlike darkening or lightening, saturate specifically boosts color brightness and vividness.
Final Answer:
Makes the color more vivid and bright -> Option B
Quick Check:
saturate() = more vivid color [OK]
Hint: Saturate = boost color brightness and vividness [OK]
Common Mistakes:
Confusing saturate() with lighten() or darken()
Thinking saturate() changes transparency
Assuming saturate() makes color dull
2. Which of the following is the correct syntax to desaturate a color by 20% in Sass?
easy
A. desaturate(#ff0000, 0.2)
B. desaturate(#ff0000 20%)
C. desaturate(#ff0000, 20%)
D. desaturate(#ff0000; 20%)
Solution
Step 1: Recall the function syntax
The desaturate() function takes two arguments separated by a comma: the color and the percentage to reduce saturation.
Step 2: Identify correct punctuation and units
The percentage must have a percent sign (%) and be separated by a comma, so desaturate(#ff0000, 20%) is correct.
The color #6699cc is a medium blue. Applying saturate($color, 30%) increases its saturation, making it more vivid.
Step 2: Compare options
A more vivid blue than #6699cc correctly describes the result. The unchanged option is incorrect because the color changes. The duller, grayer option is incorrect because saturate increases vividness. The lighter blue option is incorrect because saturate does not lighten the color.
Final Answer:
A more vivid blue than #6699cc -> Option A
Quick Check:
saturate() = more vivid color [OK]
Hint: Saturate makes colors brighter, not lighter or duller [OK]
A. Function name should be saturate, not desaturate
B. Incorrect color format
C. Percentage value should be a decimal
D. Missing parentheses around function arguments
Solution
Step 1: Check function call syntax
In Sass, functions require parentheses around their arguments. The code misses parentheses around $color and 50%.
Step 2: Verify other parts
The color format #00ff00 is valid, and the percentage is correctly given as 50%. The function name desaturate is correct for reducing saturation.
Final Answer:
Missing parentheses around function arguments -> Option D
Quick Check:
Functions need parentheses [OK]
Hint: Always use parentheses for Sass functions [OK]
Common Mistakes:
Omitting parentheses in function calls
Confusing saturate and desaturate functions
Using decimal instead of percentage
5. You want to create a button style that uses a base color #ff6600 but looks less intense on hover by reducing saturation by 40%. Which Sass code correctly achieves this?