| 28 | Creating Your Own Functions |
As well as using functions for things such as manipulating lists and maps, and color manipulation, Sass gives you the ability to create your own functions.
Functions are defined similarly to mixins. You define them using the @function directive. Then you can pass in any arguments. Inside the scope of the function, you can perform any number of tasks using standard Sass. The only main difference from a mixin is that you need to use the @return method if you want to make the function return anything.
You can see this in a simple doubling function example. A variable is passed in ($value), and the function returns the variable multiplied by two. When the function is used in the .sidebar class, it outputs 20px rather ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access