Mixins

There's an even better feature in Sass called mixins. Basically, they are a method for abstracting out repetition. For instance, it's a drag to type in vendor prefixes for CSS3, but I can declare a mixin using the @mixin keyword and then create a template chock-full of vendor prefixes. Here, I have declared a mixin named transition:

@mixin transition($property: all, $duration: .25s, $timing-function: ease) {    -webkit-transition: $property $duration $timing-function;    transition: $property $duration $timing-function;}

The mixin has parenthesis with arguments inside of it, $property, $duration, and $timing-function. Each argument has a default assigned to it, all, .25s, and ease. Then I have the -webkit- prefixed transition property and ...

Get Mastering CSS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.