Last active
July 1, 2018 16:15
-
-
Save lewismcarey/b7f9e546202357b2f7c8 to your computer and use it in GitHub Desktop.
sass function set contrasting font color based on background
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
// contrasting font color | |
@function set-font-color($color, $dark: #000, $light: #FFF) { | |
// return $dark or $light color depending on lightness of $color | |
@return if(lightness($color) > 50, $dark, $light); | |
} | |
$color: #0000FF; | |
.default { | |
background-color: $color; | |
color: set-font-color($color); | |
} | |
.custom { | |
background-color: $color; | |
color: set-font-color($color, #BADA55, #FACE0F); | |
} |
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
.default { | |
background-color: #0000FF; | |
color: #FFF; | |
} | |
.custom { | |
background-color: #0000FF; | |
color: #FACE0F; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment