Test color lightness with Sass conditionals
Ever want to test the lightness of a color with Sass? You can do that. An example use case would be a mixin for button defaults. Test the lightness of the background to determine what color the text should be.
// Test lightness of background
@if lightness($color) > lightness(#aaa)
color: darken($color, 75%)
@ else
color: $white
Note: A space was added between "@" and "else" as a workaround to Coderwall's attempt at auto linking what it deems to be an @mention.
Written by Ken Seals
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Color
Authors
Related Tags
#color
#test
#sass
#scss
#text
#mixin
#operator
#background
#gradient
#conditional
#if
#else
#lightness
#foreground
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#