前端 CSS 经典:图层放大的 hover 效果

效果

思路

设置 3 层元素,最上层元素使用 clip-path 裁剪成圆,hover 改变圆大小,添加过渡效果。

实现代码

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="initial-scale=1.0, user-scalable=no, width=device-width"
    />
    <title>document</title>
    <style>
      body {
        background: #000;
      }

      .avatar {
        background: url(../../../images/demo/img.jpg);
        background-size: cover;
        height: 200px;
        width: 200px;
        border-radius: 50%;
        cursor: pointer;
        position: relative;
      }

      .avatar::after,
      .avatar::before {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 50%;
      }

      .avatar::before {
        background: rgba(0, 0, 0, 0.5);
      }

      .avatar::after {
        background: inherit;
        clip-path: circle(0% at 50% 50%);
        transition: 0.3s;
      }

      .avatar:hover::after {
        clip-path: circle(50% at 50% 50%);
      }
    </style>
  </head>
  <body>
    <div class="avatar"></div>
    <script></script>
  </body>
</html>
相关推荐
薛定谔的猫-菜鸟程序员23 分钟前
Electron开发超详细教程(从入门到放弃)
前端·javascript·electron
最强小杰1 小时前
DeepSeek V4 Flash + Codex CLI 接入教程:原生 Responses API 适配,从配置到跑通收藏这篇就够了(2026)
java·前端·python·ai
静水leo1 小时前
使用 Whistle 拦截接口并模拟后端响应
前端
掘金者阿豪1 小时前
SQL Server数据迁移完成后,凌晨的数据库告警该怎么查?
前端·后端
JudithHuang1 小时前
React 嵌套路由与布局
前端·react.js·arcgis·react·react router
啾咪orJIUMI2 小时前
Vue 3 + SCSS 实现全屏系统门户:五栏展开与灯光联动
css
htzyl2062 小时前
前端阶梯——第四十三章、实战二:待办清单To-Do
前端·javascript·html
程序员大阳2 小时前
HTML+CSS+JS对话式实战(1)-开篇:认识我们要做的社团活动发布平台
javascript·css·html·实战·系统·平台·社团活动发布
摹客3 小时前
【3D设计】界面设计中的3D元素:应用场景+5款工具横评(含Three.js)
前端