I’m trying to loop from 1 to 12 and output some span widths for an altered grid for a particular view in an app.
$span-width: 8.21875%;
$gap: 0.125%;
@for $i from 1 through 12 {
$span-width: ($i * $span-width) + ($i * $gap) ;
.span#{$i}{
width: $span-width;
}
}
This is outputting
.span6 {
width: 6162%;
}
How do I write the sass to calculate the widths using the usual arithmetic rules?
The expression you want is this:
($i * ($span-width / 1%)) + ($i * ($gap / 1%)). Alternately, you could drop the % from your$span-width/$gapvariables.Edit: not sure why assigning the variable to the expression isn’t working (I had only tested it using @debug)
Generates this:
If you really need to reuse the variable, you might want to consider making a function for it.