1

I am trying to output the following:

.time15 {
    width: 25%;
}
.time30 {
    width: 50%;
}
.time45 {
    width: 75%;
}
.time60 {
    width: 100%;
}
.time75 {
    width: 125%;
}

All the way up to .time1440

Here is my code:

$max: 60 * 24;
$step: 15;

@for $i from 15 through ceil($max/$step) {
    $value: ($i - 1)*$step + 1;
    $width: $value / 60 * 100;
    .time{$value} {
        width: $value%
    }
}

I'm getting the following syntax error though when trying to compile:

Error: Invalid CSS after "...   &.time{$value": expected ":", was "} {"
geoffs3310
  • 5,599
  • 11
  • 51
  • 104

2 Answers2

2

The issue is that SCSS can't handle the following line:

width: $value%;

It is safer to do

width: percentage($value);

Apart from that, I think that the interpolation of the selector is also wrong. In my test I changed it to .time-#{$value} and that worked for me.

Full example:

$max: 60 * 24;
$step: 15;

@for $i from $step through ceil($max/$step) {
    $value: ($i - 1) * $step + 1;
    $width: $value / 60 * 100;

    .time-#{$value} {
        width: percentage($value);
    }
}
Wart Claes
  • 223
  • 1
  • 11
0

this maybe what you're looking for:

$max: 60 * 24;
$step: 15;

@for $i from 1 through ($max/$step) {
    $value: $step * $i;
    $width: $i * 25;
    .time#{$value} {
        width: $width + 0%
    }
}
Sonny Prince
  • 1,094
  • 7
  • 15