用css3实现一个奥运五环


本文摘自PHP中文网,作者青灯夜游,侵删。

css3实现奥运五环的方法:首先给5个div设置border-radius样式,制作五个圆环;然后使用position属性设置五个圆环的位置;最后使用z-index属性调整各环的层级关系即可。

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

五环可以利用五个统计的div来实现,要实现五环的嵌套关系,需要分别给这五个div加伪元素。

这里主要用到了两个css3属性:

1、z-index调各环的层级关系

2、transparent设置透明度

具体代码:

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

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>Title</title>

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        div{

            width: 200px;

            height: 200px;

            border: 10px solid;

            border-radius: 50%;

            float: left;

            position: absolute;

        }

        div::after{

            width: 200px;

            height: 200px;

            border: 10px solid;

            border-radius: 50%;

            float: left;

            position: absolute;

            content: "";

            left: -10px;/*相对于父级定位,但不包括border,所以利用负边距使他们重合*/

            top:-10px;

        }

        .blue{

            border-color: blue;

            top:0;

            left: 0;

        }

        .blue::after{

            border-color: blue;

            z-index: 1;

            border-bottom-color: transparent;/*将下边框设为透明,使看到的为黄色环 以下同理*/

        }

        .black{

            border-color: black;

            top:0;

            left: 230px;

        }

        .black::after{

            border-color: black;

            z-index: 1;

            border-left-color: transparent;

        }

        .red{

            border-color: red;

            top:0;

            left: 460px;

        }

        .red::after{

            border-color: red;

            z-index: 1;

            border-left-color: transparent;

        }

        .yellow{

            border-color: yellow;

            top:110px;

            left: 110px;

        }

        .yellow::after{

            border-color: yellow;

        }

        .green{

            border-color: green;

            top:110px;

            left: 340px;

        }

        .green::after{

            border-color: green;

            z-index: 1;

            border-top-color: transparent;

            border-right-color: transparent;

        }

    </style>

</head>

<body>

    <div class="blue"></div>

    <div class="black"></div>

    <div class="red"></div>

    <div class="yellow"></div>

    <div class="green"></div>

</body>

</html>

效果图:

1.png

相关学习视频推荐:css视频教程

以上就是用css3实现一个奥运五环的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

29个css面试题总结(知识点解析)

CSS3新增选择器有哪些

punctuation-trim属性怎么用

CSS3倒影效果怎么实现

html5实践-如何使用CSS3丰富图片样式的详解(二)

word-break属性怎么用

wxss和CSS3的区别是什么

transition-timing-function属性怎么用

用h5和CSS3制作全屏背景轮换播放教程

css实现页面底部固定的方法介绍(附代码)

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




打赏

取消

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

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

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

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

评论

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