Writing functions in Sass
Functions are, generally speaking, most useful when creating mixins. Conceptually, the difference between the two could be described as follows; a mixin is a tool to generate a number of property and value pairs within a CSS rule. A function, on the other hand is a self contained tool to generate a value that can be used elsewhere. The result of a function can be used in a mixin or directly into the style sheet (as they can access any globally defined variables just like a mixin can).
In Chapter 5, Responsive and Flexible Grids with Sass and Compass, I mentioned sub-pixel rounding, a common problem with responsive grids. Before Susy had an isolate-grid mixin, I used a tiny grid system I'd built called 'bb-grid' to solve ...
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