css实现炫酷流光按钮效果

一、可以使用a标签代替button按钮

 <a>liuguang</a>

二、css代码如下(利用animation实现动画效果):

* {
    margin: 0;
    padding: 0;
}

body {
    background-color: black;
}

a {
    text-decoration: none;
    position: absolute;
    /* 水平垂直居中 */
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    font-size: 24px;
    /* 角度渐变 */
    background: linear-gradient(90deg,blue,rgb(4, 171, 255),purple,rgb(223, 9, 235),rgb(163, 97, 237));
    background-size: 400%;
    width: 400px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    color: white;
    /* 大写字母转换 */
    text-transform: uppercase;
    border-radius: 50px;
    z-index: 1;
}

a:hover {
    background-color: white;
    animation: light 5s infinite;
}

@keyframes light {
    100%{
        background-position: -400% 0;
    }

三、还可利用伪元素为按钮增加模糊背景和线条流光

a::before {
    content: "";
    position: absolute;
    left: -5px;
    top: -5px;
    right: -5px;
    bottom: -5px;
    /* border: 1px solid white; */
    background: linear-gradient(90deg,blue,rgb(4, 171, 255),purple,rgb(223, 9, 235),rgb(163, 97, 237));
    background-size: 400%;
    border-radius: 50px;
    /* 背景模糊 */
    filter: blur(20px);
    z-index: -1;
}

/* 伪元素设置动画 */
a:hover::before {
    animation: light 5s infinite;
}

1.png
参考视频链接:https://b23.tv/dzblbxZ
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容