今天写跳动的红心
1、思路
首先要用css实现一个爱心的话,我是用一个正方形+两个半圆画出来的。然后用CSS3动画的animation实现跳动效果。用CSS写的话效率高。
2、界面
3、代码
CSS的:
body{
background-color: pink;
}
.wrap{
position: relative;
width: 400px;
height: 400px;
margin: 50px auto;
background-color: ;
}
.left,.right{
position: absolute;
width: 200px;
height: 200px;
background: red;
border-radius: 50%;
}
.left{
left: 35px;
}
.right{
right: 35px;
z-index: -1;
}
.bottom{
position: absolute;
bottom: 135px;
left: 100px;
width: 200px;
height: 200px;
background: red;
transform: rotate(45deg);
z-index: -1;
}
.left,.right,.bottom{
box-shadow: 0 0 40px red;
animation: heart .8s ease infinite;
}
@keyframes heart {
0%{
transform: rotate(225deg) scale(1);
box-shadow: 0 0 40px red;
}
50%{
transform: rotate(225deg) scale(1.2);
box-shadow: 0 0 70px red;
}
100%{
transform: rotate(225deg) scale(1);
box-shadow: 0 0 40px red;
}
}
HTML的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>会跳动的爱心</title>
<link href="css.css">
</head>
<body>
<div class="wrap">
<div class="left"></div>
<div class="right"></div>
<div class="bottom"></div>
</div>
</body>
</html>