M
M
myskypesla2017-03-20 13:54:10
css
myskypesla, 2017-03-20 13:54:10

Does this use of mixin have the right to life?

Hello, there is a _mixin.scss file with the code:

@mixin flex {
  display: flex;
}

@mixin align-center {
  align-items: center;
}

@mixin column {
  flex-direction: column;
}

и т.д.

There is also a main.scss file in which I do this:
.header {
  @include flex;
}

.content {
  @include flex;
  @include column;
  @include align-center;
}

.footer {
  @include flex;
}

So is it necessary to do this? Or, as usual, in each class, prescribe properties without inclusions, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Belyaev, 2017-03-20
@myskypesla

Also, this might make sense:

@mixin flex($align: null, $direction: null) {
  display: flex;
  @if $align {
    align-items: $align;
  }
  @if $direction {
    flex-direction: $direction;
  }
}

.header {
  @include flex;
}

.content {
  @include flex(center, column);
}

.footer {
  @include flex;
}

A
Alexey Sklyarov, 2017-03-20
@0example

I don’t see the point in this, you replace everything with the same, only with a slightly different design.

P
Paul Sh., 2017-03-20
@shvaika

Of course it has. However, the point of Using Mixes is to optimize a certain rule to use the "Short" approach to writing styles, mainly not even for convenience, but to increase the speed of layout. So the answer is "Yes" but in this case, in your example, you are changing the awl to soap :)

A
Alex Bond, 2017-03-21
@AlexBond

One of the ideas of mixins is the ability to quickly replace the implementation of some style in many places. Now attention, the question is - will such mixins ever change or not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question