其他分享
首页 > 其他分享> > CSS样式_跳动的心脏

CSS样式_跳动的心脏

作者:互联网

<!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">
    <link rel="stylesheet" href="index.css">
    <title>Document</title>
</head>
<body>
    <div class="heart">
        <span></span>
        <span></span>
        <span></span>
        
        <span></span>
        <span></span>
        <span></span>
        
        <span></span>
        <span></span>
        <span></span>
    </div>
</body>
</html>
/* 设置背景 */
body{
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, navy, black);
}

/* 爱心背景 */
.heart {
    width: 14em;
    height: 11em;
    /* border: 1px dashed white; */
    font-size: 20px;
    display: flex;
    justify-content: space-between;
}

.heart span{
    --c: lightblue;
    --h: 50%;
    --t: 25%;
    width: 1em;
    background-color: var(--c);
    border-radius: 0.5em;
    position: relative;
    height: var(--h);
    top: var(--t);
    border: 1px solid white;
    animation: beating 5s infinite;
}

.heart span:nth-child(1),
.heart span:nth-child(9){
    --c: orangered;
    --h: 3em;
    --t: 2.2em;
}

.heart span:nth-child(2),
.heart span:nth-child(8){
    --c:gold;
    --h: 6em;
    --t: 0.6em;
}

.heart span:nth-child(3),
.heart span:nth-child(7){
    --c:limegreen;
    --h: 8em;
    --t: 0;
}

.heart span:nth-child(4),
.heart span:nth-child(6){
    --c:dodgerblue;
    --h: 9em;
    --t: 0.8em;
}

.heart span:nth-child(5){
    --c: mediumpurple;
    --h: 9.4em;
    --t: 1.6em;
}

@keyframes beating {
    0%, 30% {
        height: var(--h);
        top: var(--t);
        background-color: var(--c);
        filter: blur(0);
        width: 1em;
    } 60%, 70% {
        height: 50%;
        top: 25%;
        filter: blur(5px);
        width: 0.1em;
    }
}

标签:em,heart,span,nth,样式,--,跳动,child,CSS
来源: https://blog.csdn.net/mango660/article/details/120313981