• 毛玻璃态按钮悬停效果


    效果展示

    在这里插入图片描述

    页面结构组成

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

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

    CSS3 知识点

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

    实现基础按钮结构

    <div class="btn">
      <a href="">阅读更多a>
    div>
    
    • 1
    • 2
    • 3
    .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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    实现按钮上的斜边背景

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

    .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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    实现基础按钮的动画

    .container .btn:hover a::before {
      transform: skewX(45deg) translateX(200%);
    }
    
    • 1
    • 2
    • 3

    实现按钮上下两个按钮

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

    .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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

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

    /* 例子中是有三个按钮,所以这里采用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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

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

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

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

    .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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    完整代码下载

    完整代码下载

  • 相关阅读:
    pandas iloc和loc
    14:00面试,14:06就出来了,问的问题过于变态了。。。
    2022年国内云管平台厂商哪家好?为什么?
    网站搭建综合ssl/访问控制
    分享自研实现的多数据源(支持同DB不同表、跨DB表、内存数据、外部系统数据等)分页查询工具类实现原理及使用
    使用Puppeteer进行游戏数据可视化
    【docker】网络模式管理
    Android 系统启动到App 界面完全展示终于明白(图文版)
    【杂记-浅谈交换机的二层转发和三层转发】
    UE4实现光束和体积雾
  • 原文地址:https://blog.csdn.net/qq_33003143/article/details/133429777