边框动画 单边追随

时间短就直接看第三个使用 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>
相关推荐
AC赳赳老秦24 分钟前
DeepSeek教育科技应用:智能生成个性化学习规划与知识点拆解教程
前端·网络·数据库·人工智能·学习·matplotlib·deepseek
布列瑟农的星空8 小时前
Playwright使用体验
前端·单元测试
卤代烃8 小时前
🦾 可为与不可为:CDP 视角下的 Browser 控制边界
前端·人工智能·浏览器
_XU9 小时前
AI工具如何重塑我的开发日常
前端·人工智能·深度学习
C_心欲无痕9 小时前
vue3 - defineExpose暴露给父组件属性和方法
前端·javascript·vue.js·vue3
鹿人戛9 小时前
HarmonyOS应用开发:相机预览花屏问题解决案例
android·前端·harmonyos
萌萌哒草头将军9 小时前
绿联云 NAS 安装 AudioDock 详细教程
前端·docker·容器
GIS之路10 小时前
GIS 数据转换:使用 GDAL 将 GeoJSON 转换为 Shp 数据
前端
朴shu11 小时前
Luckysheet 远程搜索下拉 控件开发 : 揭秘二开全流程
前端
MediaTea12 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python