0
0
Tailwindmarkup~5 mins

Group-hover (parent triggers child) in Tailwind - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does group-hover do in Tailwind CSS?

group-hover lets a parent element control the hover styles of its child elements. When you hover over the parent, the child changes style.

Click to reveal answer
beginner
How do you enable group-hover on a child element?
<p>Add the <code>group</code> class to the parent and use <code>group-hover:</code> prefix on the child's class you want to change on hover.</p>
Click to reveal answer
beginner
Why do you need the <code>group</code> class on the parent?
<p>The <code>group</code> class marks the parent so Tailwind knows to watch it for hover events and apply styles to children with <code>group-hover:</code>.</p>
Click to reveal answer
intermediate
Can group-hover be used for keyboard focus states?

No, group-hover only works for mouse hover. For keyboard focus, use group-focus instead.

Click to reveal answer
beginner
Example: What happens with this code?<br>
<div class="group">
  <p class="group-hover:text-red-500">Hello</p>
</div>

When you hover over the <div>, the <p> text color changes to red because of group-hover:text-red-500.

Click to reveal answer
What class must be added to the parent element to use group-hover on children?
Achild-hover
Bhover
Cparent-hover
Dgroup
Which of these is a correct way to change a child's background on parent hover?
A&lt;div&gt;&lt;span class="hover:group-bg-blue-500"&gt;Text&lt;/span&gt;&lt;/div&gt;
B&lt;div class="group"&gt;&lt;span class="group-hover:bg-blue-500"&gt;Text&lt;/span&gt;&lt;/div&gt;
C&lt;div class="group-hover"&gt;&lt;span class="bg-blue-500"&gt;Text&lt;/span&gt;&lt;/div&gt;
D&lt;div class="hover-group"&gt;&lt;span class="bg-blue-500"&gt;Text&lt;/span&gt;&lt;/div&gt;
Does group-hover respond to keyboard focus by default?
ANo, it only works on mouse hover
BYes, it works with keyboard focus
CYes, but only on buttons
DNo, it works on click only
What happens if you forget to add group on the parent but use group-hover on the child?
AChild styles never change on hover
BChild styles change on hover anyway
CParent gets hover styles instead
DBrowser shows an error
Which Tailwind feature allows a child to change style when the parent is hovered?
Ahover-child
Bparent-hover
Cgroup-hover
Dchild-hover
Explain how to use group-hover in Tailwind CSS to change a child's style when the parent is hovered.
Think about how the parent and child classes work together.
You got /3 concepts.
    Describe a real-life example where group-hover would improve user experience on a website.
    Consider menus or cards with icons or text that highlight on hover.
    You got /3 concepts.