代码:
<!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>.container {width: 1000px;height: 580px;margin: 50px auto;border: 1px solid green;position: relative;}.top {margin: 0 auto 0px;padding: 10px 0;background: turquoise;color: #fff;}.heart {position: relative;width: 100px;height: 90px;margin: 90px 50px;float: left;/* border: 1px solid red; */}/* 画爱心的上部分,before和after是一样的 */.heart::before,.heart::after {content: "";position: absolute;top: 40px;width: 52px;height: 80px;border-radius: 50px 50px 0 0;background: red;}/* 爱心右半部分 */.heart::before {left: 50px;transform: rotate(-45deg);transform-origin: 0 80px;}/* 爱心左半部分 */.heart::after {left: 0;transform: rotate(45deg);transform-origin: 100% 100%;}/* 定义动画 */@keyframes beat {0% {transform: scale(1);}50% {transform: scale(1.5);}100% {transform: scale(1);}}/* 应用动画 */.heart {animation: beat 1s infinite;}</style>
</head><body><div class="container"><div class="top"><h3>绘制不断跳动的心形</h3></div><div class="heart"></div><div class="heart"></div><div class="heart"></div><div class="heart"></div><div class="heart"></div></div>
</body></html>