首页 > 其他分享 >[CSS] Animate A Card's Width on Hover with Flexbox

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

时间:2024-06-04 15:24:40浏览次数:12  
标签:flex hover hovered Flexbox class Width Hover grow

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

标签:flex,hover,hovered,Flexbox,class,Width,Hover,grow
From: https://www.cnblogs.com/Answer1215/p/18230825

相关文章

  • css27 CSS Layout - width and max-width
    https://www.w3schools.com/css/css_max-width.asp CSSLayout-widthandmax-width  Usingwidth,max-widthandmargin:auto;Asmentionedinthepreviouschapter;ablock-levelelementalwaystakesupthefullwidthavailable(stretchesouttothelef......
  • css17 CSS Height, Width
    https://www.w3schools.com/css/css_dimension.aspTheCSSheightandwidthpropertiesareusedtosettheheightandwidthofanelement.TheCSSmax-widthpropertyisusedtosetthemaximumwidthofanelement.Thiselementhasaheightof50pixelsand......
  • 元素设置:hover动效边缘触发频繁闪动怎么解决
    元素设置:hover动效边缘触发频繁闪动怎么解决前言:1.我并没有深入了解,难免出错一、问题出现的原因众所周知,:hover选择器是在鼠标移到元素上时产生效果,即鼠标移到元素上,触发:hover,鼠标离开元素,恢复。因此,元素设置:hover动效边缘触发频繁闪动产生的原因就是:hover触发的样式更改......
  • 测试 width="242" height="242"
    1  width="242"height="242"         ......
  • CSS的Flexbox布局示例详解
    CSSFlexibleBoxModule(简称Flexbox)是一种现代化的布局模式,用于创建响应式的一维布局(无论是水平还是垂直)。它提供了对项目的对齐、方向、排序、尺寸调整等方面的强大控制。下面是对Flexbox布局的一些关键概念和示例代码:一、关键概念FlexContainer(弹性容器):需要添加display:f......
  • 采用flex布局,父组件width为百分比,解决子组件canvas画布width自适应问题
     创建EleResize.js文件(拷贝以下代码即可)varEleResize={ _handleResize:function(e){  varele=e.target||e.srcElement  vartrigger=ele.__resizeTrigger__  if(trigger){   varhandlers=trigger.__z_resizeListeners   if......
  • openGauss主备切换之switchover与failover
    openGauss主备切换之switchover与failoverswitchover在主备机正常时,出于维护的需要,将备机切换为主机,可保证切换过程中数据不丢失。查看集群实例主备状态:1节点为主库,2节点为备库。$gs_om-tstatus--detail[ClusterState]cluster_state:Normalredistribu......
  • clientWidth、offsetWidth、scrollWidth区别
    clientWidthclientWidth包括了元素的内边距(padding)和实际内容的宽度offsetWidthoffsetWidth包括了元素的边框(border)、内边距(padding)、滚动条(如果有)、元素的实际内容的宽度scrollWidthscrollWidth包括了元素的实际内容的宽度,但不包括边框(border)、内边距(padding)和滚动条(如果......
  • openGauss主备切换之switchover与failover
    openGauss主备切换之switchover与failoverswitchover在主备机正常时,出于维护的需要,将备机切换为主机,可保证切换过程中数据不丢失。查看集群实例主备状态:1节点为主库,2节点为备库。$gs_om-tstatus--detail[ClusterState]cluster_state:Normalredistribu......
  • echarts X轴类目名太长时隐藏,hover时显示全部
    echarts图表X轴在柱状图中,X轴类目名如果数据太长;echarts会默认进行隐藏部分字段;如果我们想让每一个类目名都显示出来,需要进行额外的处理X轴类目名太长时,默认只显示一部分类目名<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="......