16.12 Functions “@function”
Sass also provides a way to create real functions by using @function. Unlike mixins, which output a section of code, functions return a return value. Different data types such as numeric values (20, 1.125, 1.5em), strings ("text", 'text', text), colors (#fff, #ffffff, rgba (255, 255, 0, 0.75)), CSS value lists (1em, 1.5em, "Arial Narrow", Arial, sans-serif;), Boolean values (false, true), or even a null value (null) can be returned. A function is introduced with @function followed by the name of the function. The arguments of the function must be written between parentheses. Curly brackets must contain the code of the function, while @return will return a value. Here’s a simple example that converts a pixel value ...
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