• 毛玻璃 has 选择器卡片悬停效果


    效果展示

    在这里插入图片描述

    页面结构

    从上述的效果展示可以看到,页面是由多个卡片组成,并且鼠标悬停在卡片上时,会旋转用户图片并且韩式对应的用户信息框。

    CSS3 知识点

    • :has 属性的运用

    实现页面整体结构

    <div class="container">
      <div class="card" data-color="clr1">
        <div class="img_box">
          <img src="images/user-1.jpg" />
        div>
        <div class="glass">
          <h3>
            Someone
            <br />
            <span>SEO Expertspan>
          h3>
          <ul>
            <li style="--i: 1">
              <a href="#">
                <i class="fa fa-qq" aria-hidden="true">i>
              a>
            li>
            <li style="--i: 2">
              <a href="#">
                <i class="fa fa-weixin" aria-hidden="true">i>
              a>
            li>
            <li style="--i: 3">
              <a href="#">
                <i class="fa fa-weibo" aria-hidden="true">i>
              a>
            li>
            <li style="--i: 4">
              <a href="#">
                <i class="fa fa-tencent-weibo" aria-hidden="true">i>
              a>
            li>
          ul>
        div>
      div>
    div>
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36

    实现卡片基础样式

    .container .card {
      position: relative;
      width: 200px;
      height: 200px;
      border-radius: 10px;
      display: flex;
      justify-content: center;
      align-items: center;
      transition: 0.5s;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    实现用户头像样式

    .container .card .img_box {
      position: absolute;
      inset: 0;
      border-radius: 12px;
      border: 4px solid rgba(0, 0, 0, 0.2);
    }
    
    .container .card .img_box img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: 0.5s;
      border-radius: 10px;
    }
    
    .container .card:hover .img_box img {
      opacity: 0.5;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    实现用户信息框样式

    .container .card .glass {
      position: absolute;
      inset: 0;
      background: linear-gradient(#fff2, transparent);
      border: 1px solid rgba(255, 255, 255, 0.1);
      box-shadow: 0 15px 15px rgba(0, 0, 0, 0.25);
      backdrop-filter: blur(15px);
      border-radius: 10px;
      scale: 0;
      display: flex;
      flex-flow: row wrap;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      opacity: 0;
      transition: 0.5s;
    }
    
    .container .card .glass::before {
      content: "";
      display: block;
      position: absolute;
      bottom: 0;
      width: 100%;
      height: 50px;
      background: rgba(255, 255, 255, 0.05);
    }
    
    .container .card ul {
      position: absolute;
      bottom: 14px;
      width: 100%;
      display: flex;
      justify-content: center;
      gap: 15px;
    }
    
    .container .card ul li {
      list-style: none;
    }
    
    .container .card ul a {
      color: #fff8;
      font-size: 1.25em;
      scale: 0;
      transition: 0.25s;
      transition-delay: scale calc(0.2s * var(--i));
    }
    
    .container .card:hover ul a {
      scale: 1;
    }
    
    .container .card ul a:hover {
      color: #fff;
    }
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    实现对应的悬停样式

    .container .card:hover .img_box img {
      opacity: 0.5;
    }
    
    .container .card:hover {
      transform: rotate(-15deg);
    }
    
    .container .card:hover .glass {
      scale: 1;
      opacity: 1;
      transform: rotate(20deg);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    使用 has 属性修改背景颜色

    body:has(.card[data-color="clr1"]:hover) {
      background: #d18c55;
    }
    
    body:has(.card[data-color="clr2"]:hover) {
      background: #fff6a3;
    }
    
    body:has(.card[data-color="clr3"]:hover) {
      background: #eeb973;
    }
    
    body:has(.card[data-color="clr4"]:hover) {
      background: #f7f3ea;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    完整代码下载

    完整代码下载

  • 相关阅读:
    大聪明教你学Java | 在支付模块中如何防止掉单和重复支付
    dubbo项目实战代码展示
    fission源码分析--fission调用http请求流程分析
    【中国大学生计算机大赛二等奖】智能中医-中e诊简介(一)
    时间复杂度
    情绪感受一点分享
    vue3知识点:provide 与 inject
    P2432 zxbsmk爱查错,字符串线性dp
    OpenSSL在i.MX8MP开发板上的应用
    写好技术书籍
  • 原文地址:https://blog.csdn.net/qq_33003143/article/details/133577382