Just so you know, I am no expert in Sass, I am still learning.
I recently discovered the power of arguments in mixins and now I want to use them all the time :)
Description
I have been using a web font with 3 families: regular, bold, and italic. So, I created this mixin:
@mixin ffArsenal($style:regular) { font-family:arsenal-+$style, Arial, "Helvetica Neue", Helvetica, sans-serif; }
I can use it in several ways:
@include ffArsenal();
@include ffArsenal(bold);
@include ffArsenal(italic);
And the outputs are:
font-family: arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
font-family: arsenal-bold, Arial, "Helvetica Neue", Helvetica, sans-serif;
font-family: arsenal-italic, Arial, "Helvetica Neue", Helvetica, sans-serif;
Everything was going well until...
Problem
I need to specify the font-size
or line-height
. But rather than setting these properties separately, I prefer using the shorthand style.
In plain CSS, I would do something like this to add font-size
and line-height
:
font: 1.6rem/1.1 arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
The issue is that with the current mixin, I can't utilize the shorthand method.
Question
How can I enhance this font mixin to make it more flexible, allowing for options like these (which are just ideas and not functional):
@include ffArsenal();
[using default values]@include ffArsenal(1.1rem);
@include ffArsenal(1.1rem,1.8);
@include ffArsenal(1.8);
Desired outputs would be:
[default values]font: 1.6rem arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
font: 1.1rem arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
font: 1.1rem/1.8 arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
font: 1.6rem/1.8 arsenal-regular, Arial, "Helvetica Neue", Helvetica, sans-serif;
Objective
While this example uses a specific typeface, the goal is for this mixin to work seamlessly with any font family, enabling easy declaration of a font shorthand style with minimal effort and maximum efficiency.
Thank you in advance for any assistance on this matter.