Skip to content

Instantly share code, notes, and snippets.

@benhodgson87
Last active December 29, 2015 17:29
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 benhodgson87/7704637 to your computer and use it in GitHub Desktop.
Save benhodgson87/7704637 to your computer and use it in GitHub Desktop.
Sass RGBA Fallback Mixin
/**
* RGBA & Hex Fallback
*
* Takes a hex code with comma separated alpha value.
* Falls back to just the hex if no alpha is provided.
*
* Params:
* $prop: The CSS property to apply the color value to
* $color: A hex code, or bracketed Hex + Opacity figure. eg: (#fff, 0.5)
*
* Markup:
* @include color('color', #fff);
* @include color('background-color', (#fff, 0.25));
*/
@mixin color($prop, $color) {
$hex: nth($color, 1);
#{$prop}: $hex;
@if length($color) > 1 {
$alpha: nth($color, 2);
#{$prop}: rgba($hex, $alpha);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment