用css动画:敲出 爱心 给你喜欢的人

383 阅读1分钟

创建一个主盒子命名love,再运用css伪元素::before与::after,在盒子前后增加两个盒子,再利用定位transform实现功能 image.png

具体代码:

<!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>Document</title>
    <style>
        .love {
            position: relative;
            margin: 100px auto;
            width: 200px;
            height: 200px;
            transform: scale(.5) rotate(45deg);
            background-color: #f00;
            animation: nb 2s infinite;
        }

        .love::before {
            content: '';
            position: absolute;
            width: 200px;
            height: 200px;
            transform: translateX(-100px);
            border-radius: 50%;
            background-color: #f00;
        }

        .love::after {
            content: '';
            position: absolute;
            width: 200px;
            height: 200px;
            transform: translateY(-100px);
            border-radius: 50%;
            background-color: #f00;
        }

        @keyframes nb {
            25% {
                transform: scale(1) rotate(45deg);
            }

            50% {
                transform: scale(.5) rotate(45deg);
            }

            75% {
                transform: scale(1) rotate(45deg);
            }

            100% {
                transform: scale(.5) rotate(45deg);
            }
        }
    </style>
</head>

<body>
    <div class="love"></div>
</body>