毛玻璃态卡片悬停效果

效果展示

页面结构组成

页面的组成部分主要是卡片。其中卡片的组成部分主要是包括了图片和详情。

卡片的动效是鼠标悬停在卡片上时,图片会移动到左侧,并且图片是毛玻璃效果。所以我们在布局的时候图片会采用绝对布局。而详情则是基础布局。

CSS3 知识点

  • 响应式
  • 绝对布局
  • filte 属性的 invert 值使用
  • backdrop-filter 属性

实现卡片基础布局

html 复制代码
<div class="card">
  <div class="img_box">
    <img src="./images/Baseball.png" />
  </div>
  <div class="content">
    <div>
      <h3>棒球</h3>
      <p>
        一种团体球类运动,由人数最少为9人的两支队伍在一个扇形的棒球场进行攻击与守备。
        <a href="#">阅读更多</a>
      </p>
    </div>
  </div>
</div>
css 复制代码
.container .card {
  position: relative;
  display: flex;
  height: 250px;
  background: #fff;
  border-radius: 20px;
  margin: 30px 0;
  width: 45%;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

实现卡片图片样式

css 复制代码
.container .card .img_box {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  height: calc(100% - 20px);
  width: calc(100% - 20px);
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 5px 5px 30px rgba(0, 0, 0, 0.1);
  transition: 0.5s ease-in-out;
}

.container .card .img_box img {
  max-width: 100px;
  filter: invert(1);
  transition: 0.5s ease-in-out;
}

添加卡片动画效果

css 复制代码
.container .card:hover .img_box {
  height: 150px;
  width: 150px;
  left: -75px;
  top: calc(50% - 75px);
  border-radius: 10px;
}

.container .card:hover .img_box img {
  max-width: 75px;
}

响应式样式添加

css 复制代码
@media (max-width: 992px) {
  .container .card {
    width: 300px;
    height: auto;
    flex-direction: column;
    background: transparent;
    margin: -20px 0;
    box-shadow: none;
  }
  .container .card .img_box {
    position: relative;
    border-radius: 20px;
  }
  .container .card .img_box,
  .container .card:hover .img_box {
    width: 80%;
    height: 200px;
    top: 100px;
    left: 10%;
  }
  .container .card:hover .img_box {
    top: 80px;
  }
  .container .card .img_box img,
  .container .card:hover .img_box img {
    max-width: 100px;
  }
  .container .card .content {
    position: relative;
    width: 100%;
    background: #fff;
    box-shadow: none;
    border-radius: 20px;
    padding: 20px 40px 40px;
    border-top: 100px solid #fff;
  }
}

完整代码下载

完整代码下载

相关推荐
陈随易6 小时前
在Finch用了62亿词元,我认为这是新一代Agent工具之神
前端·人工智能·后端
水域安全老周6 小时前
水趣钓鱼救生衣专利拆解:两级锁紧如何解决落水人衣分离
java·前端·网络
计算机魔术师6 小时前
Anthropic CEO突然喊踩刹车,OpenAI罕见力挺:AI这辆车不能只踩油门了
前端
wing987 小时前
从codex转战workbuddy使用一周的感受
前端·人工智能·后端
EatFan7 小时前
Java接入支付宝 JSAPI 支付保姆教程(二):流程讲解与前后端代码讲解
前端·spring boot·后端·微信小程序·小程序·uni-app
梦想平凡7 小时前
百游棋牌源代码开发搭建教程(五):房间创建、座位分配与请求幂等实现
前端·javascript·数据库·源代码管理
IT_陈寒8 小时前
Redis的Set操作居然能把我的服务整挂了?
前端·人工智能·后端
计算机魔术师8 小时前
Suno 发布 v6 音乐模型,推出 v6、v6-wild、v6-mini 三个版本
前端
whyweplay8 小时前
elpis : DSL动态组件学习
前端
用户921080262869 小时前
前端 Vue 专栏 06:异步更新机制、任务队列与 nextTick
前端