边框动画 单边追随

时间短就直接看第三个使用 clip-path + animation 完成。

复制代码
<!DOCTYPE html>
<html>

<head>
    <style>
        /* 第一个 */
        .btn {
            width: 100px;
            height: 40px;
            background: yellow;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 5px;
            margin-left: 50px;
            margin-top: 50px;
            overflow: hidden;
        }

        .btn::before {
            content: '';
            width: 200%;
            height: 200%;
            background-color: red;
            animation: move 3s infinite linear;
            transform-origin: 0 0;
            position: absolute;
            top: 50%;
            left: 50%;
        }

        .btn::after {
            content: '';
            position: absolute;
            width: calc(100% - 8px);
            height: calc(100% - 8px);
            background-color: green;
        }

        .btn .name {
            z-index: 1;
        }


        @keyframes move {
            to {
                transform: rotate(1turn);
            }
        }



        /* 第二个 */

        .borderShow {
            width: 150px;
            height: 70px;
            margin: 30px;
            position: relative;
            border-radius: 6px;
            overflow: hidden;
            border: 1px solid red;
            display: flex;
            justify-content: space-around;
            align-items: center;

            &::after {
                content: '';
                position: absolute;
                top: 2px;
                left: 2px;
                width: calc(100% - 4px - 12px);
                height: calc(100% - 4px - 12px);
                text-align: center;
                border: 6px solid white;
                border-radius: 4px;
                background-color: #fff;
                animation: showRound 3s infinite linear;

            }



            /* 内部的盒子 */
            .borderShowCenter {
                position: absolute;
                top: 8px;
                left: 8px;
                width: calc(100% - 4px - 12px);
                height: calc(100% - 4px - 12px);
                text-align: center;
                border-radius: 4px;
                display: flex;
                justify-content: space-around;
                align-items: center;
                color: #fff;
                background-color: #c073ed;
                z-index: 10;
                /* 覆盖伪元素 */
            }
        }

        @keyframes showRound {

            /* box-shadow : x轴 y轴 模糊 放大 颜色; */
            0%,
            100% {
                box-shadow: 0px -66px 0px 0px #c073ed;
                /* 上 */
            }

            25% {
                box-shadow: 146px 0px 0px 0px #c073ed;
                /* 右 */
            }

            50% {
                box-shadow: 0px 66px 0px 0px #c073ed;
                /* 下 */
            }

            75% {
                box-shadow: -146px 0px 0px 0px #c073ed;
                /* 左 */
            }
        }



        /* 第三 */

        .clippath_wrap {
            /* width: 150px; */
            height: 70px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;

            &::before {
                content: "";
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                border: 2px solid gold;
                animation: clippath 3s infinite linear;     

                border-radius: 5px
            }
        }

        @keyframes clippath {

            0%,
            100% {
                clip-path: inset(0 0 95% 0);
            }

            25% {
                clip-path: inset(0 95% 0 0);
            }

            50% {
                clip-path: inset(95% 0 0 0);
            }

            75% {
                clip-path: inset(0 0 0 95%);
            }
        }
    </style>
</head>

<body>


    <div class="btn"> <span class="name">按钮名称</span></div>



    <div class="borderShow">
        <div class="borderShowCenter">按钮</div>
    </div>


    <div class="clippath_wrap">第三个按钮</div>

</body>

</html>
相关推荐
o***Z44842 分钟前
前端性能优化案例
前端
张拭心1 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白1 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
HIT_Weston1 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
百***06011 小时前
SpringMVC 请求参数接收
前端·javascript·算法
天外天-亮1 小时前
Vue + excel下载 + 水印
前端·vue.js·excel
起个名字逛街玩1 小时前
前端正在走向“工程系统化”:从页面开发到复杂产品架构的深度进化
前端·架构
用户47949283569152 小时前
React 渲染两次:是 Bug 还是 Feature?聊聊严格模式的“良苦用心”
前端·react.js·前端框架
b***74882 小时前
前端GraphQL案例
前端·后端·graphql
云飞云共享云桌面2 小时前
无需配置传统电脑——智能装备工厂10个SolidWorks共享一台工作站
运维·服务器·前端·网络·算法·电脑