【第16期】仅使用css的动画花式边框技巧

2023-03-24

html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仅使用css的动画花式边框技巧</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <div class="box" style="--i:1;"></div>
        <div class="box" style="--i:2;"></div>
        <div class="box" style="--i:3;"></div>
    </div>
</body>
</html>

css代码:

*
{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body
{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background:#000;
}
.container
{
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    gap:100px;
}
.container .box
{
    position: relative;
    width: 300px;
    height: 400px;
    background:linear-gradient(45deg,#00fe76 10%,
    transparent 10%,transparent 50%,
    #00f376 50%,#00f376 60%,
    transparent 60%,transparent 100%);
    background-size: 15px 15px;
    box-shadow: 0 0 0 10px #000,0 0 0 14px #00f376;
    filter:hue-rotate(calc(var(--i) * 90deg));
    animation:animate 0.5s linear infinite;
}
.container .box::before
{
    content:'';
    position:absolute;
    inset:20px;
    background:#000;
}
.container .box::after
{
    content:'';
    position:absolute;
    inset:30px;
    border:3px dashed #00f376;
}
@keyframes animate
{
    0%
    {
        background-position:0;
    }
    100%
    {
        background-position: 15px;
    }
}
相关内容
最新

坚持的力量

wordpress建站,视频剪辑拍摄,动画制作