S
S
Sasha2017-09-06 18:35:48
Layout
Sasha, 2017-09-06 18:35:48

How to use @mixin multiple times?

There is a sass mixin to use transition:

@mixin transition-base($property:false){
    @if(not $property){
        transition:all 250ms ease 0s;
    }
    @else{
        transition:$property 250ms ease 0s;
    }
}

So I use:
@include transition-base(padding, color, border-color);

The result is incorrectly compiled code:
transition:padding 0s ease 0s, color 0s ease 0s, border-color 250ms ease 0s;

What is the correct way to use a mixin with multiple values ​​for one argument?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2017-09-06
@userAlexander

Well, something like this
https://www.sassmeister.com/gist/1791877429a5e794c...

code if too lazy to open the link =)
@mixin transition-base($properties...){
  // Свойство transition-property по-умолчанию равно значению all
  // т.е. запись transition: 250ms ease 0s; будет
  // эквивалентна записи transition: all 250ms ease 0s;
  transition: 250ms ease 0s;
  @if length($properties) > 0 {
    transition-property: $properties;
  }
}
@include transition-base();
@include transition-base(padding, color, border-color);

A
Andrey Perov, 2017-09-06
@SnaIP

if I understand correctly...

@mixin transition($args...) {
  -webkit-transition: $args;
     -moz-transition: $args;
      -ms-transition: $args;
          transition: $args;
}

a {
  color:$color;
  @include transition(color .3s ease);
  &:hover {
    color:$color;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question