Performance: Sidebar with main content
This affects page load speed and rendering performance by how the sidebar and main content are structured and styled, impacting layout calculations and paint times.
<div class="grid grid-cols-[250px_1fr] min-h-screen"> <aside class="bg-gray-200">Sidebar</aside> <main class="p-4">Main content</main> </div>
<div class="sidebar" style="width: 250px; float: left;">Sidebar</div> <div class="main" style="margin-left: 250px;">Main content</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Float sidebar with margin main | Low (2 nodes) | Multiple reflows on resize | Medium paint cost | [X] Bad |
| CSS Grid sidebar with main | Low (2 nodes) | Single reflow on resize | Low paint cost | [OK] Good |
flex with flex-row arranges children horizontally side by side.block flex-col stacks vertically, grid-cols-1 creates one column, and inline-block does not create a flex layout.<div class="flex"> <aside class="w-1/4 bg-gray-200">Sidebar</aside> <main class="w-3/4 p-4">Main Content</main> </div>
w-1/4 means the element takes one quarter (25%) of the container width.flex, the sidebar and main content sit side by side with widths 25% and 75% respectively.<div class="flex flex-col"> <aside class="w-1/4 bg-blue-100">Sidebar</aside> <main class="w-3/4 p-4">Main Content</main> </div>
flex-col stacks children vertically, so sidebar and main appear one above the other.w-1/4 and w-3/4 are valid but ignored in vertical stacking; to place side by side, flex-row is needed.<div class="flex"> <aside class="??? bg-gray-300">Sidebar</aside> <main class="??? p-4">Main Content</main> </div>
hidden md:block on aside to hide it on small screens and show from medium screens up.w-1/4 on medium+ screens; main uses w-full on small and md:w-3/4 on medium+ to fill remaining space.hidden md:block w-1/4 for aside and w-full md:w-3/4 for main [OK]Pass the test and this pattern moves unknown