Performance: Grid item placement
Grid item placement affects how the browser calculates layout and paints grid items, impacting rendering speed and visual stability.
Jump into concepts and practice - no test required
grid-template-columns: repeat(3, 1fr); .grid-item1 { grid-column: 1 / 2; grid-row: 1 / 2; } .grid-item2 { grid-column: 2 / 3; grid-row: 1 / 2; }
grid-template-columns: repeat(3, 1fr); .grid-item { grid-column-start: auto; grid-row-start: auto; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Implicit auto-placement | Standard DOM nodes | Multiple reflows if items shift | Moderate paint cost due to layout shifts | [X] Bad |
| Explicit grid line placement | Standard DOM nodes | Single reflow | Lower paint cost with stable layout | [OK] Good |
grid-column: 2 / 4; do in a grid container?grid-column: start / end; means the item starts at the start line and ends before the end line.grid-row: start / span number;.1 / span 3, meaning start at line 1 and span 3 rows down.grid-template-columns: repeat(4, 1fr);
grid-template-rows: 100px 100px;
.item {
grid-column: 3 / 5;
grid-row: 1 / 2;
}.box {
grid-column: span 2 / 4;
grid-row: 1 / span 3;
}start / end or start / span count. Here, span 2 / 4 is reversed; span should be second.grid-row: 1 / span 3; is correct syntax to start at line 1 and span 3 rows.grid-column: 2 / 6; tries to end at line 6, outside explicit grid (may create implicit tracks).grid-column: 2 / 4; ends at line 4, spans columns 2-3 only (2 columns).grid-column: 2 / span 3; starts at line 2, spans 3 columns to line 5, fits perfectly.grid-column: span 3 / 2; has incorrect syntax (span cannot precede start).