利用伪元素+动画效果制作一个跳动的心

<!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>
        div {
            width: 200px;
            height: 200px;
            background-color: crimson;
            margin: 250px auto;
            transition: 2s;
            animation: heart 2s infinite linear;
        }
        /* 在div后面添加半个圆 */
        
        div::after {
            content: '';
            width: 200px;
            height: 200px;
            display: inline-block;
            border-radius: 50%;
            background-color: crimson;
            position: relative;
            top: -300px;
            left: 0;
        }
        
        div::before {
            content: '';
            width: 200px;
            height: 200px;
            display: inline-block;
            border-radius: 50%;
            background-color: crimson;
            position: relative;
            /* top: -120px; */
            left: -100px;
        }
        
        @keyframes heart {
            0%,
            100% {
                transform: scale(0.5) rotateZ(45deg);
            }
            50% {
                transform: scale(1.1) rotateZ(45deg);
            }
        }
    </style>
</head>

<body>
    <div id="xin"></div>
</body>

</html>

觉得不错的点个赞吧!!!

猜你喜欢

转载自blog.csdn.net/blinH/article/details/107869416
今日推荐