毛玻璃态卡片悬停效果

效果展示

页面结构组成

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

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

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;
  }
}

完整代码下载

完整代码下载

相关推荐
我不吃饼干9 天前
鸽了六年的某大厂面试题:你会手写一个模板引擎吗?
前端·javascript·面试
涵信9 天前
第一节 布局与盒模型-Flex与Grid布局对比
前端·css
我不吃饼干9 天前
鸽了六年的某大厂面试题:手写 Vue 模板编译(解析篇)
前端·javascript·面试
前端fighter9 天前
为什么需要dependencies 与 devDependencies
前端·javascript·面试
veminhe9 天前
HTML5 浏览器支持
前端·html·html5
前端fighter9 天前
Vuex 与 Pinia:全面解析现代 Vue 状态管理的进化之路
前端·vue.js·面试
snow@li9 天前
vue3-ts-qrcode :安装及使用记录 / 配置项 / 效果展示
前端·javascript·vue.js
GISer_Jing9 天前
React Next快速搭建前后端全栈项目并部署至Vercel
前端·react.js·前端框架
伍哥的传说9 天前
React 轻量级状态管理器Zustand
前端·javascript·react.js·小程序·前端框架·ecmascript
烛阴9 天前
零依赖、零框架!纯JS快速掌握 JSON 转 CSV 技巧全攻略
前端·javascript