效果图

rotation.gif

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>css按钮边框旋转动画</title>
    <style>
        body{
            background-color:  black;
        }
        div{
            width: 100px;
            height: 40px;
            color: rgb(17, 240, 240);
            border-radius: 8px;
            line-height: 40px;
            text-align: center;
            margin: 20em auto;
            position: relative;
            overflow: hidden;
           
        }
        div::before{
            content: '';
            position: absolute;
            width: 200%;
            height: 200%;
            background: rgb(17, 240, 240);
            z-index:-2;
            left: 50%;
            top: 50%;
            transform-origin: left top;
            animation: rotation 2s linear infinite;

        }
        div::after{
            content: '';
            position: absolute;
            --g:2px;
            width: calc(100% - 2*var(--g)); 
            height: calc(100% - 2*var(--g));
            background: black;
            left: var(--g);
            top: var(--g);
            border-radius: inherit;
            z-index: -1;
        }

        @keyframes rotation {
            to{
                transform: rotate(360deg);
            }
        }
    </style>
</head>
<body>
    <div>边框按钮</div>
</body>
</html>
Last modification:September 6, 2024
如果觉得我的文章对你有用,请随意赞赏