Last active
August 15, 2018 15:28
-
-
Save azinasili/afefa139e74664f87b14 to your computer and use it in GitHub Desktop.
Change text color based on background. Color is a darker/lighter hue of background.
This file contains hidden or 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
// Grab brightness of color | |
@function brightness($color) { | |
@return ((red($color)) + (green($color)) + (blue($color))) / 255 * 100%; | |
} | |
// Compare bightness and print new text color | |
@function text-color($color) { | |
@if $color == null { | |
@return null; | |
} | |
@else { | |
$color-light: mix(#ffffff, $color, 80%); | |
$color-dark: mix(#000000, $color, 60%); | |
$color-brightness: brightness($color); | |
$light-text-brightness: brightness($color-light); | |
$dark-text-brightness: brightness($color-dark); | |
@if abs($color-brightness - $light-text-brightness) > abs($color-brightness - $dark-text-brightness) { | |
@return $color-light; | |
} | |
@else { | |
@return $color-dark; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment