Using the sass:list Module to Manage Colors
📖 Scenario: You are creating a simple color palette for a website. You want to store a list of colors and then pick only the first few colors to use in your design.
🎯 Goal: Build a Sass stylesheet that uses the sass:list module to create a list of colors, set a limit for how many colors to use, extract those colors using the list module, and then apply them as background colors to CSS classes.
📋 What You'll Learn
Create a Sass list variable named
$colors with exactly these colors: #ff0000, #00ff00, #0000ff, #ffff00, #00ffffCreate a variable named
$max-colors and set it to 3Use the
list.slice() function from the sass:list module to create a new list named $selected-colors that contains only the first $max-colors colors from $colorsWrite CSS rules that create classes
.color-1, .color-2, and .color-3 with background colors from $selected-colors using a @for loop💡 Why This Matters
🌍 Real World
Managing color palettes in Sass helps keep website styles consistent and easy to update.
💼 Career
Front-end developers often use Sass list functions to handle design tokens like colors efficiently.
Progress0 / 4 steps