纯css 实现爱心效果

效果如下:
在这里插入图片描述
代码如下:

<!DOCTYPE html>
<html>
<head>
	<title>爱心</title>
</head>
<style type="text/css" >
.heart{
	width: 100px;
	height: 100px;
	transform: rotate(45deg);
	background-color: red;
	margin-top: 40px;
	margin-left: 40px;

}
.heart::before{//::before css3用法 :before css2用法
   position: absolute;//要用绝对位置
   content: '';//此项必须加,不然长度为0
   background-color: red;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;//变圆
   left: -50px;
}
.heart::after{
   position: absolute;
   content: '';//此项必须加,不然长度为0
   background-color: red;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;
   top: -50px;

}

</style>
<body>
<div class="heart"></div>	
</div>
</body>
</html>

步骤一:
先画个正方形:
html代码

.......
<body>
<div class="heart"></div>	
</div>
</body>
......

css代码:

.heart{
	width: 100px;
	height: 100px;
	background-color: red;
	margin-top: 40px;
	margin-left: 40px;

}

再在正方形里画两个圆;
css 代码如下:

.heart{
	width: 100px;
	height: 100px;
	transform: rotate(45deg);
	background-color: red;
	margin-top: 40px;
	margin-left: 40px;

}
.heart::before{
   position: absolute;
   content: '';
   background-color: pink;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;
   left: -50px;
}
.heart::after{
   position: absolute;
   content: '';
   background-color:yellow;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;
}

截图如下:
在这里插入图片描述
移动其位置:
截图如下:
在这里插入图片描述
css代码如下:

.heart{
	width: 100px;
	height: 100px;
	transform: rotate(45deg);
	background-color: red;
	margin-top: 40px;
	margin-left: 40px;

}
.heart::before{
   position: absolute;
   content: '';
   background-color: pink;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;
   left: -50px; 
}
.heart::after{
   position: absolute;
   content: '';
   background-color: yellow;
   display: block;
   width: 100px;
   height: 100px;
   border-radius: 50%;
   top: -50px;  

}

最后一步,颜色换成红色就行了(手动斜眼笑)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值