毛玻璃态按钮悬停效果

效果展示

页面结构组成

通过上述的效果展示可以看出如下几个效果

  1. 毛玻璃的按钮
  2. 按钮上斜边背景及动画
  3. 按钮上下边缘的小按钮和小按钮动画

CSS3 知识点

  • backdrop-filter 属性
  • transition 属性
  • transform 属性

实现基础按钮结构

html 复制代码
<div class="btn">
  <a href="">阅读更多</a>
</div>
css 复制代码
.container .btn {
  position: relative;
  width: 155px;
  height: 50px;
  margin: 20px;
}

.container .btn a {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 15px 35p rgba(0, 0, 0, 0.2);
  border-radius: 30px;
  /* 为了增强按钮的质感,所以在头部和底部添加了两个边线 */
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 400;
  letter-spacing: 4px;
  text-decoration: none;
  overflow: hidden;
  transition: 0.5s;
  backdrop-filter: blur(15px);
  z-index: 2;
}

实现按钮上的斜边背景

按钮的背景是一个色块,为了不让页面的结构过于复杂,所以我们在实现按钮上的斜边背景的时候,则是使用伪元素来实现。

css 复制代码
.container .btn a::before {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(to left, rgba(255, 255, 255, 0.15), transparent);
  transform: skewX(45deg) translateX(0);
  transition: 0.5s;
}

实现基础按钮的动画

css 复制代码
.container .btn:hover a::before {
  transform: skewX(45deg) translateX(200%);
}

实现按钮上下两个按钮

在上述的效果图中,按钮上下边缘是有两个小按钮的,不让页面过于复杂,我们可以使用伪元素进行实现。

css 复制代码
.container .btn::before {
  content: "";
  display: block;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -5px;
  width: 30px;
  height: 10px;
  background: #f00;
  border-radius: 10px;
  transition: 0.5s;
  transition-delay: 0s;
}

.container .btn::after {
  content: "";
  display: block;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: -5px;
  width: 30px;
  height: 10px;
  background: #f00;
  border-radius: 10px;
  transition: 0.5s;
  transition-delay: 0s;
}

为了增强质感我们添加了阴影。

css 复制代码
/* 例子中是有三个按钮,所以这里采用nth-child()属性进行其他按钮的颜色和阴影修改 */
.container .btn:nth-child(1)::before,
.container .btn:nth-child(1)::after {
  background: #ff1f71;
  box-shadow: 0 0 5px #ff1f71, 0 0 15px #ff1f71, 0 0 30px #ff1f71, 0 0 60px
      #ff1f71;
}

**说明:**要实现其他颜色的小按钮,可以在上述的例子中修改一下颜色就可以。

实现按钮上下两个按钮动画

从上述的效果图可以看出,鼠标悬停到按钮上是,两个小按钮会在宽高上进行变化。

css 复制代码
.container .btn:hover::before {
  bottom: 0;
  height: 50%;
  width: 80%;
  border-radius: 30px;
  transition-delay: 0.5s;
}

.container .btn:hover::after {
  top: 0;
  height: 50%;
  width: 80%;
  border-radius: 30px;
  transition-delay: 0.5s;
}

完整代码下载

完整代码下载

相关推荐
qq_589666051 小时前
TypeScript 完整入门教程
前端·javascript·typescript
用户059540174464 小时前
LLM对话记忆测试踩坑实录:手工回归30分钟,自动化后2分钟发现3个隐藏Bug
前端·css
Ashley的成长之路6 小时前
前端性能优化实战手册·第2篇:资源加载策略全解
前端·性能优化·资源加载·http/3·性能优化实战·资源加载优化
浅水壁虎6 小时前
vue基础(第二章 )
前端·javascript·vue.js
界面开发小八哥6 小时前
界面控件DevExtreme v26.1新版亮点——支持Angular 22
前端·javascript·angular.js·devexpress·ui开发·devextreme
Getflare6 小时前
前端 + UI 设计 + AI:这不是三个工种,是一个新三角能力模型(附自检清单)
前端·人工智能·ui
oil欧哟6 小时前
我做了一个 Vibe Coding 术语学习站:VibeHub
前端·ai·agent·独立开发·vibe coding
审小匠OpenCPAi7 小时前
银行流水核查怎么自动化?单边匹配、双向勾稽与图聚类异常检测的工程对比
java·前端·人工智能·python·审计
Revolution617 小时前
一个公共表格组件,是怎么一步步失控的
前端·前端工程化