Performance: Group-hover (parent triggers child)
This affects how CSS selectors trigger style changes on hover, impacting paint and composite stages during user interaction.
<div class="group hover:bg-gray-100"> <p class="group-hover:text-red-600">Text</p> </div>
<div class="parent" onmouseover="document.getElementById('child').style.color='red'" onmouseout="document.getElementById('child').style.color='black'"> <p id="child">Text</p> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| JavaScript hover handlers | Multiple style changes | Multiple reflows per hover | High paint cost | [X] Bad |
| Tailwind group-hover CSS | No DOM changes | No reflows | Single paint and composite | [OK] Good |
group-hover utility in Tailwind CSS do?group and group-hovergroup class is added to a parent element to enable hover state tracking.group-hover on child elementsgroup is hovered, child elements with group-hover: classes change style accordingly.group class to the parentgroup class to enable group-hover functionality.group-hover: prefix on the childgroup-hover:text-red-500 to change text color when parent is hovered.<div class='group bg-blue-300 p-4'> <button class='group-hover:bg-red-500 text-white p-2 rounded'>Click Me</button> </div>
groupdiv has class group, enabling group-hover effects on children.group-hover: classgroup-hover:bg-red-500, so its background changes when the parent is hovered.<div class='group-hover'> <p class='group-hover:text-green-600'>Hello</p> </div>
group-hover class, which is incorrect; it should have group.group-hover: is a prefix for child classes, not a class for parents. Parent must have group to enable this.group-hover to achieve this?<div class='card group p-4 border rounded'>
<button class='border group-hover:border-blue-600 p-2 relative'>
Click Me
<svg class='hidden group-hover:block absolute right-2 top-2 w-4 h-4'>...</svg>
</button>
</div>div with class card group enables group-hover effects on children.group-hover:border-blue-600, and the SVG icon toggles visibility with hidden group-hover:block.Pass the test and this pattern moves unknown