[Solved] Transition all in Tailwind css not working properly – Transition

by
Ali Hasan
reactjs tailwind-css view-transitions-api

Quick Fix: Always add the transition-all class, even when the nav is false. Wrap your logic in a template literal and add transition-all permanently using the $ operator.

The Problem:

When the toggle bar is opened, the content appears instantaneously. However, when the bar is closed, the transition animation does not function as expected. The transition only occurs when the bar is opened, not when it is closed.

The Solutions:

Solution:

In the provided code, the transition is not functioning correctly because the transition: all class is only being added when the navigation bar is closing (!nav).

To resolve this issue, the transition: all class should be added permanently. This can be achieved using a template literal to wrap the logic and always include the transition: all class:

<ul className={`transition all ${nav ? 'w-[80%] max-w-screen' : 'w-[80%] max-w-sm overflow-hidden duration-1000'}`}

Q&A

Why is that when i open the toggle bar content appears instantly but if i close it transition kciks in?

You’re conditionally adding transition-all class in your code. Adding it conditionally is wrong. Instead, add it permanently.

How to use transition-all permanently?

Wrap your logic with template literal and add transition-all within the className.

Video Explanation:

The following video, titled "The simple trick to transition from height 0 to auto with CSS - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... well, not really possible (though it is being worked on!), but luckily, there is actually a solution using CSS Grid that's really easy to ...