3

I'm trying to create a family of CSS selectors using a for loop:

@for $i from 1 through 3 {
  .bottom-#{$i} {
    bottom: #{$i}%;
  }
}

I want an output that looks like this:

.bottom-1 { bottom: 1%  }
.bottom-2 { bottom: 2%  }
.bottom-3 { bottom: 3%  }

But SASS doesn't like the % sign- it's trying to eval the statement. I'm assuming there is a way to escape a character like that, but I can't find it.

Any ideas?

Thanks

Hairgami_Master
  • 5,429
  • 10
  • 45
  • 66
  • 1
    @cimmanon Could you show me how to get the output I indicated using the technique used in the duplicate question? It doesn't appear to be possible. – Hairgami_Master Dec 19 '15 at 02:56

1 Answers1

2

You can use the percentage() function to convert the number to a percentage and then divide it by 100:

@for $i from 1 through 3 {
  .bottom-#{$i} {
    bottom: percentage($i / 100);
  }
}
Matthew Rapati
  • 5,648
  • 4
  • 28
  • 48