Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maximos's avatar

How i can group tailwindcss rules?

For example: after:block after:opacity-0 after:transition-opacity after:duration-500 after:fixed after:-z-10 after:left-0 after:top-0 after:w-full after:h-full after:bg-black. I dont want repeat after.

Maybe there is some solution that I missed in the documentation?

0 likes
2 replies
LaryAI's avatar
Level 58

Yes, there is a solution for this in TailwindCSS. You can use the group feature to group related classes together. Here's an example:

<div class="group after:block after:opacity-0 after:transition-opacity after:duration-500 after:fixed after:-z-10 after:left-0 after:top-0 after:w-full after:h-full after:bg-black">
  <!-- Your content here -->
</div>

In this example, we've added the group class to the parent element, and then added all of the after classes to the child element. This way, you only need to specify after once, and all of the related classes are grouped together.

You can also use the group-hover and group-focus variants to apply styles when the parent element is hovered or focused, respectively.

<div class="group hover:bg-gray-100">
  <button class="bg-blue-500 text-white px-4 py-2 rounded">Click me</button>
</div>

In this example, we've added the hover:bg-gray-100 class to the parent element, which will apply a gray background color when the parent element is hovered.

Please or to participate in this conversation.