Mixin: Black & White

Supplemental 49 views
0 Flares 0 Flares ×

Let’s say you need some 90% opacity white text on a 15% black opacity background. With regular CSS, you’d have to write all this:


SASS to the rescue! Let’s set up two very simple functions:

@function black($opacity){
    @return rgba(0,0,0,$opacity)
@function white($opacity){
    @return rgba(255,255,255,$opacity)

Now all I need to write is:


This saves me a ton of time all throughout my stylesheets. As an added bonus, using transparent instead of opaque colors make your elements blend in together better, and your design more coherent.
Provided by: Sacha Greif
Tagged with:
Posted in Sass


Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.


Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×