Tailwind边距动画

huangapple go评论74阅读模式
英文:

Tailwind margin animation

问题

我有这个div叠加效果。显示效果正常,但边距不正常。

<div className='relative aspect-[4/3] bg-black group'>
    <div className='transform duration-1000  mr-0 group-hover:mr-10  
        hidden group-hover:block absolute bg-white top-0 mt-[40px] right-0 p-10'>
    </div>
</div>
英文:

I have this div overlay effect. The display effect is working, but the margin is not.

&lt;div className=&#39;relative aspect-[4/3] bg-black group&#39;&gt;
    &lt;div className=&#39;transform duration-1000  mr-0 group-hover:mr-10  
        hidden group-hover:block absolute bg-white top-0 mt-[40px] right-0 p-10&#39;&gt;
    &lt;/div&gt;
&lt;/div&gt;

答案1

得分: 0

The margin hover is working (though I would recommend you transition transform properties instead of margin) but your issue is that you have hidden group-hover:block which is attempting to transition display which is not a transitionable property.

Instead you can transition opacity -> opacity-0 group-hover:opacity-100 as shown in this example link

And to use translate instead of margin transition -> group-hover:-translate-x-10 see this example link

Transitioning transform instead of margin is recommended for performance reasons. Link

英文:

The margin hover is working (though I would recommend you transition transform properties instead of margin) but your issue is that you have hidden group-hover:block which is attempting to transition display which is not a transitionable property.

Instead you can transition opacity <strike>hidden group-hover:block</strike> -> opacity-0 group-hover:opacity-100 as shown in this example https://play.tailwindcss.com/FmsPzOn6P5

And to use translate instead of margin transition <strike>mr-0 group-hover:mr-10</strike> -> group-hover:-translate-x-10 see this example https://play.tailwindcss.com/5WcZvKUFRO

Transitioning transform instead of margin is recommended for performance reasons see here https://developer.mozilla.org/en-US/docs/Learn/Performance/CSS#animating_on_the_gpu

huangapple
  • 本文由 发表于 2023年3月21日 01:24:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793436.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定