用HTML和CSS生成炫光动画卡片

这个效果结合了渐变、旋转和悬浮效果的炫酷动画示例,使用HTML和CSS实现。

一、效果

二、实现

代码如下:

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>炫光动画卡片</title>
    <style>
        body {
            margin: 0;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #0a0a0a;
            overflow: hidden;
        }

        .card {
            width: 300px;
            height: 400px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 15px;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
            cursor: pointer;
            transition: all 0.5s;
        }

        .card:hover {
            transform: scale(1.05);
            box-shadow: 0 0 30px rgba(0, 255, 255, 0.6);
        }

        .card::before {
            content: '';
            position: absolute;
            width: 150px;
            height: 140%;
            background: linear-gradient(#00fffc, #ff00ff);
            animation: rotate 4s linear infinite;
        }

        .card::after {
            content: '';
            position: absolute;
            inset: 4px;
            background: #0a0a0a;
            border-radius: 12px;
        }

        @keyframes rotate {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }

        .content {
            position: relative;
            z-index: 1;
            color: white;
            padding: 20px;
            text-align: center;
        }

        .glowing-text {
            font-size: 2em;
            font-weight: bold;
            background: linear-gradient(45deg, #ff00ff, #00fffc, #ffeb3b);
            -webkit-background-clip: text;
            color: transparent;
            animation: gradient 3s ease infinite;
        }

        @keyframes gradient {
            0% {
                background-position: 0% 50%;
            }
            50% {
                background-position: 100% 50%;
            }
            100% {
                background-position: 0% 50%;
            }
        }

        .particles span {
            position: absolute;
            width: 4px;
            height: 4px;
            background: #fff;
            border-radius: 50%;
            animation: particle 2s linear infinite;
            opacity: 0;
        }

        @keyframes particle {
            0% {
                transform: translateY(0) translateX(0);
                opacity: 1;
            }
            100% {
                transform: translateY(-100px) translateX(50px);
                opacity: 0;
            }
        }

        /* 生成随机粒子位置 */
        .particles span:nth-child(1) { left: 20%; animation-delay: 0s; }
        .particles span:nth-child(2) { left: 50%; animation-delay: 0.5s; }
        .particles span:nth-child(3) { left: 70%; animation-delay: 1s; }
        /* 可以添加更多粒子... */
    </style>
</head>
<body>
    <div class="card">
        <div class="particles">
            <span></span>
            <span></span>
            <span></span>
        </div>
        <div class="content">
            <div class="glowing-text">CSS MAGIC</div>
            <p>Hover me!</p>
        </div>
    </div>
</body>
</html>

这个动画效果包含以下特点:

  1. 科技感渐变色旋转边框

  2. 悬浮时的放大和发光效果

  3. 流动渐变色文字

  4. 背景粒子效果

  5. 磨砂玻璃质感卡片

  6. 流畅的过渡动画

实现原理:

  1. 使用伪元素创建旋转的渐变色边框

  2. 通过clip-path和overflow:hidden实现边框裁剪

  3. 使用background-clip实现文字渐变色

  4. 通过关键帧动画实现颜色流动和元素旋转

  5. 粒子效果使用绝对定位和动画延迟

  6. 使用CSS变换实现流畅的悬浮交互

你可以通过以下方式进一步自定义:

  1. 修改渐变色值来改变整体配色

  2. 调整animation-duration改变动画速度

  3. 添加更多粒子或修改粒子动画路径

  4. 修改card的尺寸和形状

  5. 添加更多交互效果(如点击效果)


相关推荐
菥菥爱嘻嘻18 小时前
输出---修改ant样式
前端·react.js·anti-design-vue
该用户已不存在18 小时前
这6个网站一旦知道就离不开了
前端·后端·github
Ai行者心易18 小时前
10天!前端用coze,后端用Trae IDE+Claude Code从0开始构建到平台上线
前端·后端
东东23318 小时前
前端开发中如何取消Promise操作
前端·javascript·promise
掘金安东尼18 小时前
官方:什么是 Vite+?
前端·javascript·vue.js
柒崽18 小时前
ios移动端浏览器,vh高度和页面实际高度不匹配的解决方案
前端
烛阴19 小时前
为什么游戏开发者都爱 Lua?零基础快速上手指南
前端·lua
大猫会长19 小时前
tailwindcss出现could not determine executable to run
前端·tailwindcss
Moonbit19 小时前
MoonBit Pearls Vol.10:prettyprinter:使用函数组合解决结构化数据打印问题
前端·后端·程序员
533_19 小时前
[css] border 渐变
前端·css