Welcome to this tutorial on building consistent color schemes with SASS/SCSS! This tutorial aims to help you understand and implement color manipulation functions in SASS/SCSS to generate professional and consistent color schemes programmatically.
By the end of this guide, you will:
Prerequisites: Basic knowledge of CSS and understanding of SASS/SCSS syntax.
In SASS/SCSS, you can use color manipulation functions like darken()
, lighten()
, saturate()
, desaturate()
to modify color values. You can also use variables and loops to generate color schemes efficiently.
Let's explore these concepts in detail.
In SASS/SCSS, you can adjust color values using built-in functions. Here are a few examples:
darken($color, $amount)
: Makes a color darker.lighten($color, $amount)
: Makes a color lighter.saturate($color, $amount)
: Increases the saturation of a color.desaturate($color, $amount)
: Decreases the saturation of a color.You can use variables to store color values and loops to generate a series of color variations.
Here's an example using the darken()
and lighten()
.
$primary-color: #3498db;
.btn {
background-color: $primary-color;
&:hover {
background-color: darken($primary-color, 10%);
}
&:active {
background-color: lighten($primary-color, 10%);
}
}
In the above code, the hover state of the button is 10% darker than the original color, and the active state is 10% lighter.
Here's an example of generating a color scheme using variables and a @for
loop.
$primary-color: #3498db;
$number-of-colors: 5;
@for $i from 1 through $number-of-colors {
.color-#{$i} {
background-color: darken($primary-color, $i * 10%);
}
}
This generates five classes (color-1
, color-2
, ..., color-5
), each with a progressively darker background color.
We've learned how to use color manipulation functions and variables and loops in SASS/SCSS to generate a consistent color scheme.
For further learning, you can explore more color manipulation functions and how to use @each
, @while
, and @if
directives in SASS/SCSS.
saturate()
and desaturate()
functions.Here's one possible solution for the first exercise:
$primary-color: #3498db;
.btn {
background-color: $primary-color;
&:hover {
background-color: saturate($primary-color, 20%);
}
&:active {
background-color: desaturate($primary-color, 20%);
}
}
In this example, the hover state of the button is 20% more saturated than the original color, and the active state is 20% less saturated.
Keep practicing and exploring further functions and features of SASS/SCSS!