Performance: Why flexbox is needed
MEDIUM IMPACT
Flexbox affects layout calculation and rendering speed by simplifying alignment and distribution of elements in a container.
display: flex; justify-content: center; align-items: center;
display: block; /* then using margin and padding hacks for alignment */ .item { margin-left: 50%; transform: translateX(-50%); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual margin/padding hacks for alignment | High (many style changes) | Multiple reflows | High due to layout thrashing | [X] Bad |
| Flexbox for alignment and distribution | Low (single style calculation) | Single reflow | Lower paint cost | [OK] Good |