Performance: Divide utilities between children
This affects how CSS utilities are applied to child elements, impacting CSS size and rendering efficiency.
Jump into concepts and practice - no test required
<div class="text-lg font-bold divide-y divide-gray-300"> <p class="mb-4">Child 1</p> <p class="mb-4">Child 2</p> <p class="mb-4">Child 3</p> </div>
<div> <p class="text-lg font-bold mb-4">Child 1</p> <p class="text-lg font-bold mb-4">Child 2</p> <p class="text-lg font-bold mb-4">Child 3</p> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated utilities on each child | Multiple style recalculations per child | Triggers reflow for each child styled | Higher paint cost due to repeated styles | [X] Bad |
| Parent-level divide utilities | Single style recalculation for parent and children | Single reflow for the divide effect | Lower paint cost due to efficient styling | [OK] Good |
space-x-4 do when applied to a parent container with multiple child elements?space-x-4 utilityfirst: prefix to target the first child element.first:bg-blue-500 applies background color blue-500 only to the first child.<div class="flex space-x-6"> <div class="p-4 bg-red-300">Box 1</div> <div class="p-4 bg-green-300">Box 2</div> <div class="p-4 bg-blue-300">Box 3</div> </div>What will be the horizontal space between Box 1 and Box 2?
space-x-6 utilityspace-x-4 on a column flex container. What is the problem?space-x-4 adds horizontal gaps, which have no effect here.space-y-4 should be used instead.first: and last:.first:border-red-500 and last:border-green-500 are correct pseudo-class prefixes. The base border-blue-500 applies to all children.first:border-red-500 last:border-green-500 border-blue-500 applies base border last, which overrides first/last styles. border-blue-500 first:border-red-500 last:border-green-500 !important uses invalid !important. border-blue-500 first-child:border-red-500 last-child:border-green-500 uses invalid selectors.