Skip to content

Instantly share code, notes, and snippets.

@richthegeek
Created March 18, 2012 17:49
Show Gist options
  • Save richthegeek/2078534 to your computer and use it in GitHub Desktop.
Save richthegeek/2078534 to your computer and use it in GitHub Desktop.
Safe color mixin
@function mix-alpha($color, $bg) {
@return mix(opacify($color, 1), opacify($bg, 1), alpha($color) * 100);
}
@mixin safe-color($color, $bg) {
background: mix-alpha($color, $bg);
background: $color;
}
body {
@include safe-color(rgba(255, 0, 0, 0.5), #000);
}
@richthegeek
Copy link
Author

Output:
body { background: #7f0000; background: rgba(255, 0, 0, 0.5); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment