css 流动边框,蚂蚁线

蚂蚁线的效果
在这里插入图片描述

蚂蚁线的解剖效果
在这里插入图片描述

总结:通过4条虚线的移动产生效果

此次内容只对顶部虚线进行解析

1、盒子相对定位 4条虚线绝对相对

2、transform: translateX(-200px)的作用

-200px 200px指的是正方形的边长 -200px 就是让虚线向左移动200px

没有transform: translateX(-200px)在这里插入图片描述
有transform: translateX(-200px)
在这里插入图片描述

最后通过 animation: toRight 8s linear infinite;

使其有动画的移动会远处

完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            position: relative;
            width:200px;
            height:200px;
            background: #b4affd;
            overflow: hidden;
        }
        .box>span{
            position: absolute;
        }
        .box>span:nth-child(4n+1){/*上*/
            left:0;
            top:0;
            height: 0px;
            width:400px;
            border-top:5px dashed black;
            animation: toRight 8s linear infinite;
            transform: translateX(-200px);
            animation-direction:alternate;
        }
        @keyframes toRight{
            to{
                transform: translateX(0px);
            }
        }
        .box>span:nth-child(4n+2){/*右*/
            right:0;
            top:0;
            height: 400px;
            width:0px;
            border-right:5px dashed black;
            animation: toBottom 8s linear infinite;
            transform: translateY(-200px);
            animation-direction:alternate;
        }
        @keyframes toBottom{
            to{
                transform: translateY(0px);
            }
        }
        .box>span:nth-child(4n+3){/*下*/
            left:0;
            bottom:0;
            height: 0px;
            width:400px;
            border-bottom:5px dashed black;
            animation: toLeft 8s linear infinite;
            transform: translateX(0px);
            animation-direction:alternate;
        }
        @keyframes toLeft{
            to{
                transform: translateX(-200px);
            }
        }
        .box>span:nth-child(4n){/*左*/
            left:0;
            top:0;
            height: 400px;
            width:0px;
            border-left:5px dashed black;
            animation: toTop 8s linear infinite;
            transform: translateY(0px);
            animation-direction:alternate;
        }
        @keyframes toTop{
            to{
                transform: translateY(-200px);
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
</body>
</html>

来源于扑克飞剑大佬

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值