Performance: Color scale generation
This affects the CSS file size and rendering speed by controlling how many color variations are generated and used in styles.
@for $i from 1 through 10 { .color-scale-#{$i} { color: lighten($base-color, $i * 5%); } }
@for $i from 1 through 100 { .color-scale-#{$i} { color: lighten($base-color, $i * 1%); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| 100-step color scale | Minimal (CSS only) | 0 | High due to many style rules | [X] Bad |
| 10-step color scale | Minimal (CSS only) | 0 | Low due to fewer style rules | [OK] Good |
$base-color: #336699;
$scale-color: lighten($base-color, 20%);
.my-class {
background-color: $scale-color;
}@function generate-scale($color, $steps) {
@for $i from 1 through $steps {
.color-#{$i} {
color: lighten($color, $i * 10%);
}
}
}Pass the test and this pattern moves unknown