Can this end code be optimized in scss?

$color_1:black;
$color_2:red;
$color_3:yellow;

.txt_1{
  color: $color_1;
}
.txt_2{
  color: $color_2;
}
.txt_3{
  color: $color_3;
}
Feb.11,2022

naming can be more semantic and easy to use.


can be written like this.

$color_1:black;
$color_2:red;
$color_3:yellow;
$colorlist: $color_1 $color_2 $color_3;
@for $i from 1 through 3 {
  .txt_-sharp{$i} { color: nth($colorlist, $i); }
}
Menu