This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Change Styles on Multiple Elements with Tailwinds group-hover

    Simon VrachliotisSimon Vrachliotis

    Sometimes, you want to update styles for multiple children elements when hovering over a parent. The group-hover class in Tailwind lets you do just that in a very elegant way!

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:00 Here's a simple UI card. It looks nice and all, but we want the background to go purple on hover. As you can see, the text becomes unreadable. How do you tackle this problem with utility classes? We could add a hover text white class on both the headline and the paragraph, but that's not really what we want.

    00:18 Tailwind offers a group hover utility class for this scenario. You give the parent element a class of group. Then, each child element that needs to react to the parent hover state gets a group hover prefix class. Check it out. Now, all update when the parent element, the one with the group class, is hovered.

    Discuss

    Discuss