前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >炫彩流光按钮 CSS + HTML

炫彩流光按钮 CSS + HTML

作者头像
小丞同学
发布2021-08-16 15:30:45
3.7K0
发布2021-08-16 15:30:45
举报
文章被收录于专栏:小丞前端库

炫彩流光按钮

写在前面

你若要喜爱你自己的价值,你就得给世界创造价值。——歌德

效果图

三个绝美的样例

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

HTML代码

代码语言:javascript
复制
<div class="box">
        <button class="btn">button</button>
</div>

实现过程

  1. 给按钮添加一个渐变的背景颜色
  2. 将背景的大小放大到原来的若干倍,可以自己设定,这样做是为了让渐变的效果更明显,同时后续实现流光的效果
  3. 给字体设置text-shadow属性,多设置几个可以增加亮度
  4. 当鼠标经过时,实现流光的效果,通过动画改变背景的位置来实现,相当于拖动背景,让按钮显示不一样的颜色
  5. 当鼠标经过时添加光晕的效果,通过伪元素,建一个比原先按钮大一点的盒子,先利用透明度为0隐藏起来,当鼠标经过时,改变透明度为1,同时设置filter属性,添加模糊距离,从而实现光晕的效果

CSS代码

代码语言:javascript
复制
@keyframes move {
    0% {
        background-position: 0%;
    }
    100% {
        background-position: 100%;
    }
}
.btn {
    position: relative;
    width: 300px;
    height: 110px;
    color: white;
    line-height: 80px;
    font-size: 60px;
    font-family: sans-serif;
    text-transform: uppercase;//转化为大写字母
    text-align: center;
    border-radius: 40px;
    background: linear-gradient(90deg,rgb(242, 97, 94),rgb(234, 150, 104),rgb(251, 200, 2),rgb(174, 9, 43),rgb(108, 40, 243),rgb(212, 4, 128),rgb(85, 132, 206));
    background-size: 400%;
    border: none;
    outline: none;
    text-shadow: 0 0 3px white,
                 0 0 3px white,
                 0 0 3px white;//加亮
    z-index: 1;
}
.btn:hover {
    animation: move 2s linear alternate infinite;
}
.btn::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    width: 310px;
    height: 120px;
    background: linear-gradient(90deg,rgb(242, 97, 94),rgb(234, 150, 104),rgb(251, 200, 2),rgb(174, 9, 43),rgb(108, 40, 243),rgb(212, 4, 128),rgb(85, 132, 206));
    background-size: 400%;
    opacity: 0;
    border-radius: 45px;
    transition: .6s;
    z-index: -1;
}
.btn:hover::before {
    filter: blur(10px);
    opacity: 1;
    animation: move 2s linear alternate infinite;
}

完整代码

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>炫彩流光</title>
    <style>
        @keyframes move {
            0% {
                background-position: 0%;
            }
            100% {
                background-position: 100%;
            }
        }
        * {
            margin: 0;
            padding: 0;
        }
        body {
            background-color: black;
        }
        .box {
            width: 400px;
            height: 400px;
            margin: 100px auto;
        }
        .btn {
            position: relative;
            width: 300px;
            height: 110px;
            color: white;
            line-height: 80px;
            font-size: 60px;
            font-family: sans-serif;
            text-transform: uppercase;//转为大写字母
            text-align: center;
            border-radius: 40px;
            background: linear-gradient(90deg,rgb(242, 97, 94),rgb(234, 150, 104),rgb(251, 200, 2),rgb(174, 9, 43),rgb(108, 40, 243),rgb(212, 4, 128),rgb(85, 132, 206));
            background-size: 400%;
            border: none;
            outline: none;
            text-shadow: 0 0 3px white,
                         0 0 3px white,
                         0 0 3px white;
            z-index: 1;
        }
        .btn:hover {
            animation: move 2s linear alternate infinite;
        }
        .btn::before {
            content: '';
            position: absolute;
            top: -5px;
            left: -5px;
            width: 310px;
            height: 120px;
            background: linear-gradient(90deg,rgb(242, 97, 94),rgb(234, 150, 104),rgb(251, 200, 2),rgb(174, 9, 43),rgb(108, 40, 243),rgb(212, 4, 128),rgb(85, 132, 206));
            background-size: 400%;
            opacity: 0;
            border-radius: 45px;
            transition: .6s;
            z-index: -1;
        }
        .btn:hover::before {
            filter: blur(10px);
            opacity: 1;
            animation: move 2s linear alternate infinite;
        }
    </style>
</head>
<body>
    <div class="box">
        <button class="btn">button</button>
    </div>
</body>
</html>

End

以上就是炫彩流光按钮的全部内容了

先相信自己,然后别人才会相信你。——罗曼·罗兰

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/03/02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 炫彩流光按钮
    • 写在前面
      • 效果图
        • HTML代码
          • 实现过程
            • CSS代码
              • 完整代码
                • End
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档