I can't get Sass to output the !important
keyword with a mixin, I've tried:
@include font-size($font-size-sml) !important;
And:
@include font-size($font-size-sml !important);
It always throws an error.
EDIT
I ended up with this which works fine:
@mixin font-size($font-size, $sledge-hammer: "") {
font-size: $font-size #{$sledge-hammer};
font-size: ($font-size / $base-font-size)+rem #{$sledge-hammer};
line-height: ceil($font-size / $base-line-height) * ($base-line-height / $font-size);
}
As mentioned in the other answers, you can include mixins in other mixins. In addition, you can scope your mixins. Scoping mixins means that you can have multiple mixins named the same in different scopes without conflicts arising.
You can't add !important
to whole mixin in SASS (It is possible in LESS I think) like you're trying to do in first example.
Second example works for me (you can pass !important with a parameter), I mean, if you use $font-size-sml
directly as a property value it works, so maybe check your syntax.
But if it's really not working for you, you can do something with flag, set a important_flag as a mixin parameter and then use if-else statement in mixin. Something like this:
@mixin large-text($prop, $is_imp: false) {
@if $is_imp == false {
font-size: $prop;
} @else {
font-size: $prop !important;
}
}
Maybe it's not a glamorous way to do it, but it works ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With