I am writing a mixin like this:
@mixin box-shadow($top, $left, $blur, $color, $inset:\"\") {
-webkit-box-shadow:
You can put the property with null as a default value and if you don't pass the parameter it will not be interpreted.
@mixin box-shadow($top, $left, $blur, $color, $inset:null) {
-webkit-box-shadow: $top $left $blur $color $inset;
-moz-box-shadow: $top $left $blur $color $inset;
box-shadow: $top $left $blur $color $inset;
}
This means you can write the include statement like this.
@include box-shadow($top, $left, $blur, $color);
Instead of writing it like this.
@include box-shadow($top, $left, $blur, $color, null);
As shown in the answer here
@mixin box-shadow($args...) {
@each $pre in -webkit-, -moz-, -ms-, -o- {
#{$pre + box-shadow}: $args;
}
#{box-shadow}: #{$args};
}
And now you can reuse your box-shadow even smarter:
.myShadow {
@include box-shadow(2px 2px 5px #555, inset 0 0 0);
}
is to pass $args...
to the @mixin
.
That way, no matter how many $args
you will pass.
In the @input
call, you can pass all args needed.
Like so:
@mixin box-shadow($args...) {
-webkit-box-shadow: $args;
-moz-box-shadow: $args;
box-shadow: $args;
}
And now you can reuse your box-shadow in every class you want by passing all needed args:
.my-box-shadow {
@include box-shadow(2px 2px 5px #555, inset 0 0 0);
}
here is the solution i use, with notes below:
@mixin transition($trans...) {
@if length($trans) < 1 {
$trans: all .15s ease-out;
}
-moz-transition: $trans;
-ms-transition: $trans;
-webkit-transition: $trans;
transition: $trans;
}
.use-this {
@include transition;
}
.use-this-2 {
@include transition(all 1s ease-out, color 2s ease-in);
}
With sass@3.4.9 :
// declare
@mixin button( $bgcolor:blue ){
background:$bgcolor;
}
and use without value, button will be blue
//use
.my_button{
@include button();
}
and with value, button will be red
//use
.my_button{
@include button( red );
}
works with hexa too
I am new to css compilers, hope this helps,
@mixin positionStyle($params...){
$temp:nth($params,1);
@if $temp != null{
position:$temp;
}
$temp:nth($params,2);
@if $temp != null{
top:$temp;
}
$temp:nth($params,3);
@if $temp != null{
right:$temp;
}
$temp:nth($params,4);
@if $temp != null{
bottom:$temp;
}
$temp:nth($params,5);
@if $temp != null{
left:$temp;
}
.someClass{
@include positionStyle(absolute,30px,5px,null,null);
}
//output
.someClass{
position:absolute;
top: 30px;
right: 5px;
}