简单边框动画

在layui论坛上闲逛时发现了一个用css3实现的边框动画,故简单实现了下。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .container{position: relative;width: 200px;height: 100px;line-height: 100px;text-align: center;border: 1px solid #ccc;}
        span{position: absolute;display: inline-block;content: none;width: 0;height: 0;font-size: 0;border: 0;transition: .5s;}
        /*该动画实则是通过四个span标签分别设置边框,然后再增加宽度或者高度来实现的*/
        .top{top: 0;right: 0;border-top: 2px solid #000;}
        .right{bottom: 0;right: 0;border-right: 2px solid #000;}
        .bottom{bottom: 0;left: 0;border-bottom: 2px solid #000;}
        .left{top: 0;left: 0;border-left: 2px solid #000;}
        
        .container:hover .top,.container:hover .bottom{width: 200px;}
        .container:hover .left,.container:hover .right{height: 100px;}
        
        /*animate动画,因为上面运用了transition动画,故下面的动画注释了*/
        /*.top,.bottom{animation: bt .6s infinite ease-in-out;}
        .left,.right{animation: bl .6s infinite ease-in-out}*/
        @keyframes bt{
            from{
                width: 0;
            }
            25%{
                width: 50px;
            }
            50%{
                width: 100px;
            }
            75{
                width: 150px;
            }
            to{
                width: 200px;
            }
        }

        @keyframes bl{
            from{
                height: 0;
            }
            25%{
                height: 25px;
            }
            50%{
                height: 50px;
            }
            75%{
                height: 75px;
            }
            to{
                height: 100px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        KOBE BRYANT
        <span class="top"></span>
        <span class="right"></span>
        <span class="bottom"></span>
        <span class="left"></span>
    </div>
</body>
</html>

也可以看看这篇文章

转载于:https://www.cnblogs.com/11lang/p/6746467.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值