A
A
Alexey Donets2015-08-27 02:41:47
css
Alexey Donets, 2015-08-27 02:41:47

Why Use Loops in Sass?

I'm very interested in why Sass has these cycles and what their practical application is, if we still get just css at the output. What's the point of them?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-08-27
Protko @Fesor

Why do you need cycles? Say

var arr = [];
for(var i =0; i < 10; i++) {
   arr.push(i);
}

this can be written simply:
var arr = [];
arr.push(0);
arr.push(1);
arr.push(2);
//...
arr.push(9);

the meaning is the same, and the second piece of code will run faster... why the loop then?

D
Denis Ineshin, 2015-08-27
@IonDen

Simplifies writing constructions of the form:

.class_1 {...}
.class_2 {...}
.class_3 {...}
.class_4 {...}
...
.class_N {...}

You're tempted to write. And on cycles, one or two and you're done.
Or, for example, you might want to place 100 images in a circle, with position: absolute and top-left coordinates. How to calculate? In a cycle, according to the formula.

D
Denis Malinochkin, 2015-08-27
@DiAsCrafts

For example, yesterday users of my library (material design color palette for Less, Scss, Stylus) wanted to generate selectors for themselves and had to write a mixin to generate them. Nobody wants to write ~100 selectors manually. In the same way, for example, a grid is built in Bootstrap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question