3D 毛玻璃晶质见证卡

效果展示



页面结构

从上面的效果展示来看,页面主要成员是一张卡片,并且卡片上有三个小矩形,而小矩形上会展示对应的内容。

当鼠标悬停在卡片上时,卡片会随着鼠标的移动而改变视角。

CSS3 知识点

  • transform-style 属性的 preserve-3d 值运用
  • transform 属性的 translateZ 值运用
  • VanillaTilt.js 与 translateZ 的 3D 视角运用

实现页面整体布局

html 复制代码
<div class="container">
  <div class="box">
    <div class="elements bg"></div>
    <div class="elements img_box">
      <img src="./images/user-2.png" />
    </div>
    <div class="elements name">
      <h2>Someone Famous</h2>
    </div>
    <div class="elements content">
      <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem quis
        magni porro et unde eos consectetur esse cum voluptatibus dolor.
        Voluptatem eligendi, veniam molestias incidunt quod corporis provident
        magnam iure.
      </p>
    </div>
    <div class="card"></div>
  </div>
</div>

实现卡片的基础样式

css 复制代码
.box {
  position: relative;
  border-radius: 20px;
  transform-style: preserve-3d;
}

.box .card {
  position: relative;
  background: rgba(255, 255, 255, 0.1);
  width: 300px;
  min-height: 400px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.75);
  border-left: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 20px;
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.05);
  transform-style: preserve-3d;
}

编写三个小矩形的基础样式

css 复制代码
.elements {
  position: absolute;
  top: 50px;
  left: -30px;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.1);
  transform: translateZ(80px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.75);
  border-left: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.05);
}

编写装饰类小矩形的样式及鼠标悬停样式

css 复制代码
.elements.bg::before {
  content: "";
  display: block;
  position: absolute;
  inset: 0;
  background: url(./images/left_quote.png) no-repeat center;
  background-size: 90%;
  opacity: 0;
  transition: 0.5s;
}

.box:hover .elements.bg::before {
  opacity: 1;
}

编写用户头像小矩形框样式及鼠标悬停样式

css 复制代码
.elements.img_box {
  top: 0;
  left: initial;
  right: 60px;
  width: 120px;
  height: 120px;
  padding: 10px;
  transform: translateZ(120px);
}

.elements.img_box img {
  position: absolute;
  width: calc(100% - 20px);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.75);
  border-left: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.05);
  opacity: 0;
  transition: 0.5s;
}

.box:hover .elements.img_box img {
  opacity: 1;
}

编写用户姓名的样式和鼠标悬停样式

css 复制代码
.elements.name {
  top: 235px;
  left: initial;
  right: 0;
  width: 100%;
  height: 10px;
  padding: 10px;
  text-align: center;
  transform: translateZ(180px);
  background: transparent;
  backdrop-filter: blur(0px);
  border: none;
  box-shadow: none;
  color: #644651;
  transition: 0.5s;
  opacity: 0;
  transition-delay: 0.25s;
}

.box:hover .elements.name {
  opacity: 1;
  top: 145px;
}

编写用户信息卡片和鼠标悬停样式

css 复制代码
.elements.content {
  top: initial;
  left: initial;
  bottom: 0;
  right: -20px;
  width: 85%;
  min-height: 200px;
  padding: 10px;
  transform: translateZ(180px);
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
}

.elements.content p {
  position: relative;
  color: #fff;
  font-size: 0.85em;
  opacity: 0;
  transition: 0.5s;
  transition-delay: 0.5s;
  color: #644651;
}

.box:hover .elements.content p {
  opacity: 1;
}

完整代码下载

完整代码下载

相关推荐
0思必得06 小时前
[Web自动化] Selenium处理动态网页
前端·爬虫·python·selenium·自动化
东东5166 小时前
智能社区管理系统的设计与实现ssm+vue
前端·javascript·vue.js·毕业设计·毕设
catino6 小时前
图片、文件的预览
前端·javascript
layman05288 小时前
webpack5 css-loader:从基础到原理
前端·css·webpack
半桔8 小时前
【前端小站】CSS 样式美学:从基础语法到界面精筑的实战宝典
前端·css·html
AI老李8 小时前
PostCSS完全指南:功能/配置/插件/SourceMap/AST/插件开发/自定义语法
前端·javascript·postcss
_OP_CHEN8 小时前
【前端开发之CSS】(一)初识 CSS:网页化妆术的终极指南,新手也能轻松拿捏页面美化!
前端·css·html·网页开发·样式表·界面美化
啊哈一半醒8 小时前
CSS 主流布局
前端·css·css布局·标准流 浮动 定位·flex grid 响应式布局
PHP武器库9 小时前
ULUI:不止于按钮和菜单,一个专注于“业务组件”的纯 CSS 框架
前端·css
电商API_180079052479 小时前
第三方淘宝商品详情 API 全维度调用指南:从技术对接到生产落地
java·大数据·前端·数据库·人工智能·网络爬虫