css怎么做个红色的心


本文摘自PHP中文网,作者藏色散人,侵删。

css做红色的心的方法:首先创建一个HTML示例文件;然后定义一个div,并通过css属性画出一个圆形;接着做出一个正方形;最后通过css transform中的rotate属性实现爱心样式即可。

本教程操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。

用css做一个爱心

摘要:HTML的标签都比较简单,入门非常的迅速,但是CSS是一个需要我们深度挖掘的东西,里面的很多样式属性掌握几个常用的便可以实现很好看的效果,下面我便教大家如何用CSS做一个爱心。

  前期预备知识:

  1.   明白正方形的画法。
  2. 明白圆形的画法。
  3. 明白什么是定位。
  4. 明白怎么旋转。

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

1

2

3

4

5

6

7

8

9

.disc1{

    width: 100px;

    height: 100px;

    border:1px solid red;

    background-color: red;

    margin:300px 0px 0px 300px;

    border-radius:100%;

    float:left;

}

  由于我们的爱心是由两个圆和一个正方形组成的,所以我们还需要再来一个圆形。

1

2

3

4

5

6

7

8

9

10

11

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

}

【推荐:《css视频教程》】  

第三步我们就需要做一个正方形了。

1

2

3

4

5

6

7

8

9

10

.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里面。具体代码如下:

1

2

3

4

.main{

    transform: rotate(45deg);

    margin: 300px;

}

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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<!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>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

*{

    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;

}

以上就是css怎么做个红色的心的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

csscss3的区别是什么

css怎么将鼠标变小手样式

css怎么实现内容不可选

css如何让盒子浮动

css selector什么意思

使用css有什么优势

你可能不了解的css容器查询!!

css怎么让div居中

css column-rule-style属性怎么用

css column-rule-width属性怎么用

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...