P
P
Peter2017-08-01 14:59:48
css
Peter, 2017-08-01 14:59:48

How did you do an arithmetic progression in less?

.style{
  position: absolute;
  &-1{
    left: 65px;
  }
  &-2{
    left: 80px;
  }
  &-3{
    left: 95px;
  }
}

Each element is shifted by 15px. It’s somehow not beautiful to prescribe with hands, but I didn’t understand how to set an increase of 15.
Is it even possible to do this in less? If so, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2017-08-01
@volkov_p_v

.generate-styles(3);

.generate-styles(@n, @i: 1) when (@i =< @n) {
  [email protected]{i} {
    left: 50px + @i * 15px;
  }
  .generate-styles(@n, (@i + 1));
}

The output will give this:
.style-1 {
  left: 65px;
}
.style-2 {
  left: 80px;
}
.style-3 {
  left: 95px;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question