Skip to content

Instantly share code, notes, and snippets.

@kmck
Created June 9, 2016 21:36
Show Gist options
  • Save kmck/c0176adac84cf5e1ff20b7ff3eca726c to your computer and use it in GitHub Desktop.
Save kmck/c0176adac84cf5e1ff20b7ff3eca726c to your computer and use it in GitHub Desktop.
SCSS mixin to flatten a color against another color
// ## matte
//
// Calculate the color created by flattened the input color against a base color with an opacity
//
// @param {Color} $color: foreground color
// @param {Color} [$matte]: background color (or `transparent`) to matte the foreground against
// @param {Number} [$opacity]: mixing opacity of the foreground color, analogous to layer opacity
// in an image editor
// @return {Color} the matted color
//
@function matte($color, $matte: #ffffff, $opacity: 1) {
@if ($matte == transparent) {
@return rgba($color, opacity($color) * $opacity);
} @else {
@return mix(rgba($color, 1), rgba($matte, 1), 100 * opacity($color) * $opacity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment