`color:value` warning when using `sass`

Asked 2 years ago, Updated 2 years ago, 101 views

app/assets/stylesheets/style.css.scss has the following definitions:

@each$color in red, purple, blue, green, yellow, orange {
  .c_#{$color}{
    color:$color;
  }
}

The style is applied, but the following warning appears in the terminal:

You don't mean to use the color value 'blue' in interpolation here.
It may end up presented as #0000ff, which will like produce invalid CSS.
Always quote color names when using them as strings (for example, "blue").
If you really want to use the color value here, use'"+$color'.

As stated in the warning, we modified it as follows, but the style is not applied and it is invalid.

@each$color in red, purple, blue, green, yellow, orange {
  .c_#{$color}{
    "" +$color;
  }
}

How do I fix this?

environment:Rails 4.2.10

ruby-on-rails ruby sass

2022-09-30 21:35

1 Answers

I'm not telling you to use '+$color' as '+$color' but
Warning to add properties such as color:
Therefore, if you do the following, there will be no error.

@each$color in red, purple, blue, green, yellow, orange {
  .c_#{$color}{
    color:$color
  }
}


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.