Performance: Nesting rows and columns
Nesting rows and columns affects the DOM size and layout calculation time, impacting page rendering speed and visual stability.
<div class="row"> <div class="col"> Content </div> <div class="col"> Additional Content </div> </div>
<div class="row"> <div class="col"> <div class="row"> <div class="col"> Content </div> </div> </div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Deeply nested rows and columns | High (many nested divs) | Multiple reflows per nested level | High paint cost due to layout thrashing | [X] Bad |
| Flat row with multiple columns | Low (few divs) | Single reflow | Low paint cost | [OK] Good |
.row must be inside a .container or .col for proper alignment..row should be placed inside a .col to maintain the grid structure and spacing..row inside a .col element -> Option A.row inside a .col element [OK].row inside .col for layout [OK].row directly inside another .row.col directly inside .container without a row.container inside .row.col to allow nesting inside it..col, a .row is correctly nested, and inside that row, columns can be placed.<div class='col'><div class='row'><div class='col'></div></div></div>[OK]
.row inside .col, then add .col inside row [OK].row instead of .col for nesting.row directly inside another .row.col inside .col without a row<div class='container'>
<div class='row'>
<div class='col-6'>Left</div>
<div class='col-6'>
<div class='row'>
<div class='col-6'>Top Right</div>
<div class='col-6'>Bottom Right</div>
</div>
</div>
</div>
</div>col-6, so they split the container horizontally 50% each.col-6 columns, which split that right half horizontally into two equal parts side by side.<div class='container'>
<div class='row'>
<div class='row'>
<div class='col'>Nested Column</div>
</div>
</div>
</div>.row must be inside a .col when nested..row directly inside another .row without wrapping it in a .col, which breaks the grid structure..row is nested directly inside another .row without a .col -> Option B.row is nested directly inside another .row without a .col [OK].row directly inside another .row [OK].col is optional inside rowscol-6, we need a nested row with two full-width columns stacked vertically.<div class='row'>
<div class='col-6'>
<div class='row'>
<div class='col-12'>Top Left</div>
<div class='col-12'>Bottom Left</div>
</div>
</div>
<div class='col-6'>Right Side</div>
</div> nests a .row inside the left .col-6 and uses two .col-12 columns stacked vertically, which is correct. The right .col-6 is a single section.<div class='row'>
<div class='col-6'>
<div class='row'>
<div class='col-12'>Top Left</div>
<div class='col-12'>Bottom Left</div>
</div>
</div>
<div class='col-6'>Right Side</div>
</div> [OK]Pass the test and this pattern moves unknown