Skip to content

Instantly share code, notes, and snippets.

@stormwarning
Last active December 29, 2015 20:39
Show Gist options
  • Save stormwarning/7725427 to your computer and use it in GitHub Desktop.
Save stormwarning/7725427 to your computer and use it in GitHub Desktop.
Generate a colour value from an RGBa value.
/**
* A very simple, pragmatic Sass mixin for generating any property with an rgba() colour
* and its associated fallback (sourced from the original rgba() colour).
*
* Do not use if you require a fallback vastly different from the rgba().
*
* 1. Strip the alpha value and write out a solid rgb() color.
* 2. Drop the red, green, blue, and alpha paramaters into the relevant places.
*
h1 {
@include rgba(color, 255, 0, 0, 0.5)
}
*
* @link: http://jsfiddle.net/csswizardry/h3eG8/
*/
@mixin rgba($property, $red, $green, $blue, $alpha) {
#{$property}: rgb(#{$red}, #{$green}, #{$blue}); /* [1] */
#{$property}: rgba(#{$red}, #{$green}, #{$blue}, #{$alpha}); /* [2] */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment