1、用css画一个圆形
.disc1{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin:300px 0px 0px 300px
border-radius:100%
float:left
}
2、由于爱心是由两个圆和一个正方形组成的,所以还需要再来一个圆形
.disc2{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin:250px 0px 0px 0px
border-radius:100%
float:left
position: relative
right: 50px
}
3、心型下方就需要做一个正方形
.square{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin: 300px 0px 0px 0px
float: left
position: relative
right: 152px
}
4、做完这些的效果已经基本上出来了,但是还需要调整一下爱心的角度,这时就需要用到css样式中的transform中的rotate属性了。
由于需要把三个div都旋转角度,所以把这三个div放在一个div里面。具体代码如下:
.main{
transform: rotate(45deg)
margin: 300px
}
全部代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
*{
margin: 0px
padding: 0px
}
.main{
transform: rotate(45deg)
margin: 300px
}
.disc1{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin:300px 0px 0px 300px
border-radius:100%
float:left
}
.disc2{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin:250px 0px 0px 0px
border-radius:100%
float:left
position: relative
right: 50px
}
.square{
width: 100px
height: 100px
border:1px solid red
background-color: red
margin: 300px 0px 0px 0px
float: left
position: relative
right: 152px
}
</style>
</head>
<body>
<div class="main">
<div class="disc1"></div>
<div class="disc2"></div>
<div class="square"></div>
</div>
</body>
</html>
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>a heart demo </title>
<style type="text/css" rel="stylesheet">
.container {
width: 300px
height: 240px
margin: auto
position: relative
}
@keyframes heartbeat-left {
0%, 100% {
transform: scale(0.95) rotate(-45deg)
transform-origin: 0 100%
}
50% {
transform: scale(1.00) rotate(-45deg)
transform-origin: 0 100%
}
}
@keyframes heartbeat-right {
0%, 100% {
transform: scale(0.95) rotate(45deg)
transform-origin: 100% 100%
}
50% {
transform: scale(1.00) rotate(45deg)
transform-origin: 100% 100%
}
}
.left, .right {
position: absolute
top: 0
width: 150px
height: 240px
border-radius: 150px 150px 0 0
background: lightcoral
animation-iteration-count: infinite
animation-delay: 500ms
animation-timing-function: cubic-bezier(0, 0, 0, 1.74)
animation-play-state: running
animation-duration: 2000ms
}
.left {
animation-name: heartbeat-left
left: 150px
transform: rotate(-45deg)
transform-origin: 0 100%
box-shadow: inset 6px 6px 0 6px rgba(255, 255, 255, 0.1)
}
.right {
right: 150px
transform: rotate(45deg)
animation-name: heartbeat-right
transform-origin: 100% 100%
box-shadow: inset -6px -6px 0 6px rgba(255, 255, 255, 0.1)
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
心形的话可以通过这样来实现
<div class="heart"></div> .heart{position:relativewidth:100pxheight:100pxmargin:100px}.heart:before,
.heart:after{position:absolutecontent:""display:blockwidth:30pxheight:50pxborder-radius:30px 30px 0 0background:#F00}
.heart:before{-webkit-transform:rotate(-45deg)}
.heart:after{right:56px-webkit-transform:rotate(45deg)}