用纯CSS画一颗爱心

来源 | https://www.cnblogs.com/liu-en-ci/p/6721963.html

CSS是一个需要深度挖掘的东西,里面有很多样式属性,掌握几个常用的便可以实现很好看的效果,例如用CSS画爱心。

前期预备知识:

  1. 明白正方形的画法。

  2. 明白圆形的画法。

  3. 明白什么是定位。

  4. 明白怎么旋转。

话不多说,先教大家怎么用css画一个圆形。

.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;}

做完这些的效果已经基本上出来了,但是我们还需要调整一下爱心的角度,这时就需要用到我们css样式中的transform中的rotate属性了。

我们由于需要把三个p都旋转角度,所以我们把这三个p放在一个p里面。具体代码如下:

.main{    transform: rotate(45deg);    margin: 300px;}

做到现在,我们的爱心就已经做出来咯。效果图如下:

全部代码如下(包含HTML代码和CSS代码)

<!DOCTYPE html><html>    <head>        <meta charset="utf-8" />        <link href="css/square.css" rel="stylesheet" type="text/css">        <title></title>    </head>    <body>        <div class="main">            <div class="disc1"></div>            <div class="disc2"></div>            <div class="square"></div>        </div>    </body></html>
*{    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;}

本文完〜

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值