Performance: Why grid is needed
MEDIUM IMPACT
Grid layout affects how quickly the browser can calculate and paint complex page layouts, impacting page load and rendering speed.
/* Using CSS Grid for layout */ .container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
/* Using floats and manual margins for layout */ .container { width: 100%; } .item { float: left; width: 33.33%; margin-bottom: 20px; } .clearfix::after { content: ''; display: block; clear: both; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Floats with clearfix | High (many nodes with float and clear) | Multiple reflows per item | Higher paint cost due to layout thrashing | [X] Bad |
| CSS Grid layout | Low (simple container with grid) | Single reflow for layout | Lower paint cost with efficient compositing | [OK] Good |