Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate height property tailwindcss

Is there a way to animate the height property, this my simple code but the height isn't animated it just changed instantly

<div>
<a className="group  flex items-center w-full pr-4 pb-2 text-gray-600 transition-transform transform rounded-md hover:translate-x-1 focus:outline-none focus:ring collapsed" onClick={() => { setSecond(!secondElement) }}>
  <span className="ml-1 text-white text-xl group"> TITLE </span>
 </a>
</div>
<div className={`transition-all duration-300 ease-in-out transform ${!secondElement ? 'h-0' : 'h-auto'} bg-blue mt-2 space-y-2 px-7`}>
 <a
    role="menuitem"
    className="block p-2 text-sm text-white transition-colors duration-200 rounded-md dark:text-light dark:hover:text-light hover:text-gray-700">1</a>
 <a
  role="menuitem"
  className="block p-2 text-sm text-white transition-colors duration-200 rounded-md dark:hover:text-light hover:text-gray-700">2</a>
   </div>
</div>
like image 338
Maxime Ghéraille Avatar asked Mar 09 '21 19:03

Maxime Ghéraille


People also ask

How do I set the height on my PX tailwind?

​Use h-{number} or h-px to set an element to a fixed height.

Can you animate height CSS?

For animate the "height" of element with CSS Transitions you need use "max-height". If use the "height: auto", the effect not works. Is necessary some value for the CSS create a CSS animate, and you can use "max-height" with a great value for emulate this effect.

How do you animate in tailwind?

To create a wiggle animation you can add the keyframes in tailwind. config. js file. With the @keyframes we define the Tailwind animation for when it is 0% and 100% complete, we want to rotate the element 3 degrees left, and when it is 50% complete we want to rotate the element 3 degrees right.

How do you use percentage in tailwind?

You can use them by appending square brackets containing a CSS value (e.g. [80%] ) to a prefix such as p- for padding or mr- for margin-right.


Video Answer


1 Answers

By default, Tailwind does not provide transition-property utilities for the height property. You'll need to add it to your tailwind.config.js file for the transition to work.

module.exports = {
    theme: {
        extend: {
            transitionProperty: {
                height: 'height'
            }
        }
    }
}

From Tailwind v3, you can now use an arbitrary value to generate a one-off transition-property on the fly, without changing your tailwind.config.js file.

<div class="transition-[height]">
    <!-- ... -->
</div>
like image 77
juliomalves Avatar answered Oct 19 '22 20:10

juliomalves