Skip to content

Instantly share code, notes, and snippets.

@gpluess
Created August 13, 2020 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpluess/3d37a690fd232c73e1d930048b7ff205 to your computer and use it in GitHub Desktop.
Save gpluess/3d37a690fd232c73e1d930048b7ff205 to your computer and use it in GitHub Desktop.
Easy SCSS color-function #sass #scss #css
// 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