用CSS样式制作跳动的心的效果

使用CSS制作beating heart的动画

  • 首先制作一个位置完全居中的红色正方形。
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>A beating heart</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}#div1 {
				width: 100px;
				height: 100px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -50px;
				margin-top: -50px;
			}
			</style>
	</head>
<div id="div1">
			</div>
  • 将正方形添加两个半圆改造成一颗爱心

以下为部分代码

#lefthalf {
				width: 50px;
				height: 100px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -100px;
				margin-top: -50px;
				float: left;
				border-radius: 50px 0px 0px 50px;
			}

			#righthalf {
				width: 100px;
				height: 50px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -50px;
				margin-top: -100px;
				border-radius: 50px 50px 0px 0px;
			}

由于整个图像是倾斜的,我们需要将整个心形正立,因此做旋转处理,并加入跳动的动画,最终的完整代码如下:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>A beating heart</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}

			#div1 {
				width: 100px;
				height: 100px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -50px;
				margin-top: -50px;
			
			}

			#lefthalf {
				width: 50px;
				height: 100px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -100px;
				margin-top: -50px;
				float: left;
				border-radius: 50px 0px 0px 50px;
			}

			#righthalf {
				width: 100px;
				height: 50px;
				background-color: red;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -50px;
				margin-top: -100px;
				border-radius: 50px 50px 0px 0px;
			}

			@keyframes scaleDraw {

				50% {
					transform: rotate(45deg) scale(0.7);

				}

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

				}
			}


			#heart {
				width: 100px;
				height: 150px;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-top: -40px;
				transform: rotate(45deg);
				-webkit-animation-name: scaleDraw;
				animation-iteration-count: infinite;
				-webkit-animation-duration: 1s;
			}
		</style>
	</head>
	<body>
		<div id="heart">
			<div id="lefthalf">
			</div>
			<div id="div1">
			</div>
			<div id="righthalf">

			</div>
		</div>
	</body>
</html>

效果图:在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值