Performance: Fluid spacing with calculations
MEDIUM IMPACT
This affects page load speed and rendering smoothness by controlling how spacing adapts to screen size without causing layout shifts.
$min-spacing: 1rem; $max-spacing: 2rem; $min-vw: 320; $max-vw: 1200; $fluid-spacing: calc(#{$min-spacing} + (#{$max-spacing} - #{$min-spacing}) * ((100vw - #{$min-vw}px) / (#{$max-vw} - #{$min-vw}))); .element { margin: $fluid-spacing; }
$spacing: 16px; .element { margin: $spacing; } @media (min-width: 768px) { $spacing: 32px; .element { margin: $spacing; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed spacing with media queries | Minimal | Multiple on resize | Moderate | [X] Bad |
| Fluid spacing with calc() and viewport units | Minimal | Single smooth reflow on resize | Low | [OK] Good |