A SCSS mixin to create RGB fallbacks for RGBa styles.
- By: @cballenar
- Last updated: January 4th, 2014
This mixin takes up to 4 arguments (minimum of two)
- $property: the css property to be used, e.g.: 'border'
- $attributes: the additional attributes, e.g.: '1px solid'
- $color: the translucent color to be used, e.g.: 'rgba(240,20,200,.5)'
- $background: color that will be used in mix, e.g.: '#DADADA'
You're required to enter at least the $property and $color variables, so you end up with the following options:
- @include alpha-me($property, $color);
- @include alpha-me($property, $color, $background);
- @include alpha-me($property, $attributes, $color);
- @include alpha-me($property, $attributes, $color, $background);
.element {
@include alpha-me( color, rgba(black,.5) );
@include alpha-me( background-color, rgba(#dffa14,.5), #529ef0);
@include alpha-me( box-shadow, 1px 1px 2px, rgba(white, .25));
@include alpha-me( border, 3px solid, rgba(240,20,200,.5), #DADADA); }
.element {
color: #7F7F7F;
color: rgba(0, 0, 0, 0.5);
background-color: #98CC82;
background-color: rgba(223, 250, 20, 0.5);
box-shadow: 1px 1px 2px #FFF;
box-shadow: 1px 1px 2px rgba(255, 255, 255, 0.25);
border: 3px solid #E577D1;
border: 3px solid rgba(240, 20, 200, 0.5); }
- If no background color is specified, white is used by default
- We can use the rgba SASS function to enter the translucent color in other formats
- rgba(red, .5)
- rgba(#dffa14, .75)
- Can you think of a better name for the mixin? I'm not in love with it...
=======================================================================================
Thanks to John W. Long (@johnwlong) whose work is the heart of this mixin. (http://thesassway.com/intermediate/mixins-for-semi-transparent-colors)
=======================================================================================