Performance: Masonry-style grid
This affects page load speed and rendering performance by how the browser calculates layout and paints items in a masonry grid.
<div class="columns-3 gap-4">
<!-- Items with varying heights -->
</div><div class="grid grid-cols-3 gap-4"> <!-- Items with varying heights --> </div> <script> // JavaScript to reorder items for masonry effect const container = document.querySelector('div'); // complex JS layout logic </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| JavaScript masonry layout | High (DOM reorder) | Multiple per item | High (many repaints) | [X] Bad |
| CSS columns masonry | Low (no reorder) | Single layout pass | Low (native paint) | [OK] Good |
columns-3 do in a masonry-style grid layout?columns-3 classgap- or text-.columns-3 means 3 vertical columns [OK]gap-4 class adds consistent horizontal and vertical spacing between grid items.space-x-4 adds only horizontal spacing between flex items, m-4 adds margin around an element, and columns-4 sets column count, not spacing.gap-4 for spacing in grids [OK]<div class="columns-2 gap-3"> <div class="bg-blue-300 p-4">Item 1</div> <div class="bg-green-300 p-4">Item 2</div> <div class="bg-red-300 p-4">Item 3</div> <div class="bg-yellow-300 p-4">Item 4</div> </div>
gap-3 adds spacing between columns and rows. Each item has padding and background color but no fixed height, so heights can vary.columns-2 means 2 vertical columns [OK]<div class="columns-3 gap-4"> <div class="p-4">Item A</div> <div class="p-4">Item B</div> <div class="p-4">Item C</div> </div>
gap-4 is valid, and columns-3 works for masonry. Flex is not needed here because columns use CSS multi-column layout.columns-1 md:columns-2 lg:columns-4 sets the number of columns based on screen size: 1 for small, 2 for medium, 4 for large.gap-6 adds consistent spacing between items across all screen sizes.Pass the test and this pattern moves unknown