Skip to content

Instantly share code, notes, and snippets.

@kaelifa
Created November 9, 2012 08:04
Show Gist options
  • Save kaelifa/4044367 to your computer and use it in GitHub Desktop.
Save kaelifa/4044367 to your computer and use it in GitHub Desktop.
A CodePen by kaelifa. Setting colour opacity using rbga - A function where I can set the RGB colour value once as a variable and then amend the opacity on a case-by-case basis
<div class="example-colour75">
<p>Example colour with 75% opacity</p>
</div>
<div class="example-colour50">
<p>Example colour with 50% opacity</p>
</div>
<div class="example-colour25">
<p>Example colour with 25% opacity</p>
</div>
@import "compass";
@function colourOpacity($opacity, $a) {
@return rgba(
nth(append($a, $opacity), 1),
nth(append($a, $opacity), 2),
nth(append($a, $opacity), 3),
$opacity
);
}
$color-example: 11,72,107;
.example-colour75 {
background: colourOpacity(0.75, $color-example);
}
.example-colour50 {
background: colourOpacity(0.5, $color-example);
}
.example-colour25 {
background: colourOpacity(0.25, $color-example);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment