Performance: Color values and manipulation
This affects the browser's paint and composite stages by changing how colors are calculated and rendered.
$base-color: #3498db; $light-color: #5dade2; $semi-transparent: rgba(52, 152, 219, 0.5); .element { background-color: $light-color; border-color: $semi-transparent; }
$base-color: #3498db; .element { background-color: lighten(darken($base-color, 10%), 15%); border-color: rgba($base-color, 0.5); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Nested color functions in Sass | No extra DOM nodes | 0 | High due to complex color blending | [X] Bad |
| Precomputed color variables in Sass | No extra DOM nodes | 0 | Low paint cost | [OK] Good |
lighten() function increases the lightness of a color, making it lighter.darken() makes colors darker, rgba() changes transparency, and mix() blends two colors.darken() function takes two arguments separated by a comma: a color and a percentage without quotes.$base: #0000ff; $mix-color: #ff0000; $result: mix($base, $mix-color, 50%);
mix() function blends two colors by a given weight. 50% means equal parts of both colors.$color: lighten(#123456 10%);
lighten() function requires two arguments separated by a comma: a color and a percentage.#123456 and 10%, causing a syntax error.$primary: #0066cc; and add 50% transparency. Which Sass code correctly does this?lighten($primary, 30%) to increase brightness by 30%.rgba(..., 0.5) to set 50% opacity.Pass the test and this pattern moves unknown