Sass control directive with decimal numbers

后端 未结 2 1234
有刺的猬
有刺的猬 2021-01-17 03:38

I\'m trying to get a sass function going:

$times: 0.10 0.20 0.30 0.40 0.50 0.60 0.70 0.75 0.80 0.90;

@each $value in $times{
  .is-hidden-#{$value}{
    @in         


        
2条回答
  •  太阳男子
    2021-01-17 03:48

    Your desired output is invalid CSS. From the CSS validator:

    In CSS1, a class name could start with a digit (".55ft"), unless it was a dimension (".55in"). In CSS2, such classes are parsed as unknown dimensions (to allow for future additions of new units) To make "1s" a valid class, CSS2 requires the first digit to be escaped ".\31s" [1s]

    There are many times where Sass will give you errors when you try to generate invalid CSS. To generate valid results, you need to compose the selector using integers and adding the escaped decimal point like this:

    @for $i from 1 through 9 {
      .is-hidden-0\.#{$i}s {
        @include hide($i / 10 * 1s);
      }
    }
    

提交回复
热议问题