css-赛博朋克风动画组件

css-赛博朋克风动画组件 目录


前言

  • Tutorials收费课程中的一种实现。

  • 实现思路:

    • 先绘制盒子
    • 制作动画,通过颜色位置变化来实现流转
    • -webkit-box-reflect: below 2px linear-gradient(transparent,#0005);实现倒影
  • 所用功能:

    • border-sizing
    • justify-content
    • display
    • overflow
    • transition
    • -webkit-box-reflect
    • box-shadow
    • animation

结果展示

在这里插入图片描述

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cyberpunk Button</title>
    <style>
        *
        {
            margin: 0;
            padding: 0;
            font-family: consolas;
            box-sizing: border-box;
        }
		
        body
        {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #050801;
        }
		
        a
        {
            position: relative;
            display: inline-block;
            padding: 25px 30px;
            margin: 0 20px;
            color: #03e9f4;
            text-transform: uppercase;
            letter-spacing: 4px;
            text-decoration: none;
            font-size: 24px;
            overflow: hidden;
            transition: 0.5s;
            -webkit-box-reflect: below 2px linear-gradient(transparent,#0005);
        }
        a:hover
        {
            background: #03e9f4;
            color: #050801;
            box-shadow: 0 0 5px #03e9f4,
            0 0 25px #03e9f4,
            0 0 50px #03e9f4,
            0 0 200px #03e9f4;
        }
        a span
        {
            position: absolute;
            display: block;
        }
        a span:nth-child(1)
        {
            top: 0;
            left: -100%;
            width: 100%;
            height: 2px;
            background: linear-gradient(90deg,transparent,#03e9f4);
            animation: animate1 1s linear infinite;
            animation-delay: 0s;
        }
        @keyframes animate1
        {
            0%
            {
                left: -100%;
            }
            50%,100%
            {
                left: 100%;
            }
        }
        a span:nth-child(3)
        {
            bottom: 0;
            right: -100%;
            width: 100%;
            height: 2px;
            background: linear-gradient(270deg,transparent,#03e9f4);
            animation: animate3 1s linear infinite;
            animation-delay: 0.5s;
        }
        @keyframes animate3
        {
            0%
            {
                right: -100%;
            }
            50%,100%
            {
                right: 100%;
            }
        }
        a span:nth-child(2)
        {
            top: -100%;
            right: 0;
            width: 2px;
            height: 100%;
            background: linear-gradient(180deg,transparent,#03e9f4);
            animation: animate2 1s linear infinite;
            animation-delay: 0.25s;
        }
        @keyframes animate2
        {
            0%
            {
                top: -100%;
            }
            50%,100%
            {
                top: 100%;
            }
        }
        a span:nth-child(4)
        {
            bottom: -100%;
            left: 0;
            width: 2px;
            height: 100%;
            background: linear-gradient(360deg,transparent,#03e9f4);
            animation: animate4 1s linear infinite;
            animation-delay: 0.75s;
        }
        @keyframes animate4
        {
            0%
            {
                bottom: -100%;
            }
            50%,100%
            {
                bottom: 100%;
            }
        }


        a:nth-child(1)
        {
            filter: hue-rotate(290deg);
        }

        a:nth-child(3)
        {
            filter: hue-rotate(110deg);
        }
    </style>
</head>
<body>
<a href="#">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    btn1
</a>
<a href="#">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    btn2
</a>
<a href="#">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    btn3
</a>
</body>
</html>
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
赛博朋克格的背景通常都比较复杂,包含了许多几何形状、线条、渐变和特效等元素。以下是一种可能的实现方式: HTML结构: ```html <div class="cyber-bg"> <div class="grid"></div> <div class="lines"></div> <div class="dots"></div> <div class="glow"></div> </div> ``` CSS样式: ```css .cyber-bg { position: relative; width: 100%; height: 100vh; overflow: hidden; background-color: #1b1b1b; } .grid { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px), linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px); background-size: 20px 20px; } .lines { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(to right, rgba(255, 255, 255, 0.02) 2px, transparent 2px), linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 2px, transparent 2px); background-size: 50px 50px; animation: lines 10s linear infinite; } .dots { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px), radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px); background-position: 0 0, 25px 25px; background-size: 50px 50px; } .glow { position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; border-radius: 50%; background-color: rgba(0, 255, 255, 0.1); opacity: 0; animation: glow 5s linear infinite; } @keyframes lines { from { background-position: 0 0, 0 0; } to { background-position: 50px 50px, 25px 25px; } } @keyframes glow { 0% { opacity: 0; } 50% { opacity: 0.5; } 100% { opacity: 0; } } ``` 解释: 1. `.cyber-bg` 是最外层的容器,设置宽度为100%、高度为100vh,背景颜色为 #1b1b1b(深灰色)。 2. `.grid` 是一个全屏的网格背景,使用渐变和 `background-size` 属性实现。 3. `.lines` 是一组斜线背景,使用渐变和 `animation` 属性实现。通过动画将背景的位置随时间移动,形成动态效果。 4. `.dots` 是一组圆点背景,使用径向渐变和 `background-position` 属性实现。 5. `.glow` 是一个发光的圆形背景,使用圆形边框和透明度实现。通过动画将透明度随时间变化,形成发光效果。 6. 使用 `position: absolute` 属性将每个背景元素定位到父容器的左上角,使它们叠加在一起形成复杂的背景效果。 这只是一种实现方式,您可以根据自己的需求和创意进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值