HTML+CSS之流光按钮
本文最后更新于160 天前,其中的信息可能已经过时,如有错误请发送邮件到jimmy6646az@outlook.com

HTML

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>流光按钮</title>
    <link rel="stylesheet" href="css/流光按钮.css" />
  </head>
  <body>
    <a href="#">sunbutton</a>
  </body>
</html>

CSS

* {
    /* 初始化 取消页面的内外边距 */
    padding: 0;
    margin: 0;
}

body {
    /* 弹性布局 让页面元素垂直+水平居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    /* 让页面占屏幕总高 */
    height: 100vh;
    background-color: #000;
}

a {
    /* 相对定位 */
    position: relative;
    width: 400px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    font-size: 24px;
    color: #fff;
    /* 圆角属性 */
    border-radius: 50px;
    /* 背景渐变色 */
    background-image: linear-gradient(to right, #03a9f4, #f441a5, #ffeb3b, #09a8f4);
    /* 背景渐变色大小 */
    background-size: 400%;
    z-index: 1;
}

/* 下面设计 发光效果 */
a::before {
    content: '';
    position: absolute;
    top: -5px;
    bottom: -5px;
    left: -5px;
    right: -5px;
    border-radius: 50px;
    /* 背景渐变色 */
    background-image: linear-gradient(to right, #03a9f4, #f441a5, #ffeb3b, #09a8f4);
    /* 背景渐变色大小 */
    background-size: 400%;
    /* 元素的位置 底层或者顶层  -值表示底层 + 值表示顶层 */
    z-index: -1;
    /* 设置模糊度 显示发光效果 */
    filter: blur(20px);
}

a:hover {
    /* 动画 名称 时间 infinite 是无限次播放 */
    animation: sun 8s infinite;
}

a:hover::before {
    animation: sun 8s infinite;
}

@keyframes sun {
    100% {
        /* 背景位置 */
        background-position: -400% 0;
    }
}

实际效果演示:流光按钮

作者:阿阳热爱前端的个人空间-阿阳热爱前端个人主页-哔哩哔哩视频

代码来源:https://github.com/ayangweb/HTML-CSS-case

当您点击页面上的外链进行跳转时,请注意该外链所指向的网站不受我们控制,请谨慎点击并自行评估风险,对于因点击外链所产生的任何损失、纠纷或其他后果,我们不承担相关责任。

上一篇
下一篇