Created
August 13, 2020 07:23
-
-
Save gpluess/3d37a690fd232c73e1d930048b7ff205 to your computer and use it in GitHub Desktop.
Easy SCSS color-function #sass #scss #css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a map with our colors: | |
$colors: ( | |
primary:#f37021, | |
secondary:#b4341d, | |
); | |
// Declaring colors as global variables of page | |
:root { | |
@each $name, $color in $colors { | |
--color-#{$name}: #{$color}; | |
} | |
} | |
/* Creating a function that returns our color, | |
in accordance with the syntax of css-variables */ | |
@function color($color-name) { | |
@return var(--color-#{$color-name}); | |
} | |
// Usage | |
body{ | |
color: color(primary); | |
background-color: color(secondary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment