[CSS] Animate A Card's Width on Hover with Flexbox

The cards on the DJI site have an effect where the hovered card expands and the other cards shrink:

Card behavior on the DJI website

In order to emulate this effect we'll use Flexbox.

We'll start by adding the classes flex-1 and hover:grow-[2] to the li element, and removing the group-hover class.

The flex-1 class acts similarly to fr, which is a unit relative to the available space. Since all of the li items have flex-1, they take equal parts divided by 4.

When we hover, the hover:grow-[2] class sets the flex-grow to 2, which means that the hovered card will take up twice the space of the other cards:

 
 
<li
  key={index}
  class="group relative h-[500px] w-full overflow-hidden rounded-2xl bg-rose-300 flex-1 hover:grow-[2]"
>

The hovered card takes up too much space

You can see here that the hovered card is taking up a lot of space.

Adjusting hover:grow- to 1.25 will make for a more subtle effect:

<li
  key={index}
  class="group relative h-[500px] w-full overflow-hidden rounded-2xl bg-rose-300 flex-1 hover:grow-[1.25]"
>

 

The card takes up an appropriate amount of space

posted @   Zhentiw  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-06-04 [AWS - DA] Cognito
2021-06-04 [AWS -DA] SAM & CDK
2021-06-04 [AWS - DA] Lambda - PART 2
2021-06-04 [AWS - DA] VPC
2020-06-04 [Python] Putting Code on PyPi
2016-06-04 [Redux] Navigating with React Router <Link>
2016-06-04 [Redux] Adding React Router to the Project
点击右上角即可分享
微信分享提示