V
V
Vadim Belkin2015-11-20 02:44:26
Less
Vadim Belkin, 2015-11-20 02:44:26

How to reassign a variable in LESS depending on a condition?

I enter a variable with color. And depending on the condition in the mixin, I change it.

@value: true;
@color: #000;
.change-color() when (@value = true) {
  @color:  #fff;
}
.change-color();

But in the end, the variable returns the color set at the very beginning. How to implement conditional reassignment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-11-20
@27cm

Because the variables are declared in different scopes.
As an option to do this:

@value: true;
.mixin (@color) {
    // Тут все правила, использующие @color...
}
& when (@value = false) {
    .mixin(#000);
}
& when (@value = true) {
    .mixin(#FFF);
}

stackoverflow.com/questions/29496933/less-conditio...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question