css画图形

css画图,常见只是利用2个小技巧。
1:border画多边形
2:border-radiou画曲边图形

理解border一张图就行了
border边框的分布特性

1
2
3
4
5
6
7
8
9
div{
width:100px;
height:100px;
background: red;
border-top: 100px solid green;
border-left:50px solid yellow;
border-bottom: 100px solid blue;
border-right: 30px solid violet;
}

理解border-radious
参考:border-radious详解

链接这么长,可以压缩一下吗?

来,少年,画完这个图还有三个图!

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
div{
margin:20px;
text-align: center;
background: red;
line-height: 100px;
}
.square{
width:100px;
height:100px;
}
.rectangle{
width:200px;
height:100px;
}
.circle{
width:100px;
height:100px;
border-radius:50px;
}
.oval{
width:200px;
height:100px;
border-radius: 100px / 50px; /*水平半径 垂直半径*/
}
.diamond{
margin:0;
width:500px;
height:100px;
background: white;
overflow: hidden;
}
.diamond .left_triangle{
margin:0;
width:0;
height:0;
border-bottom: 50px solid yellow;
border-right:50px solid yellow;
border-top:50px solid transparent;
border-left:50px solid transparent;
float:left;
background: white;
}
.diamond .square{
margin:0;
width:100px;
height:100px;
background: yellow;
float:left;
}
.diamond .right_triangle{
margin:0;
width:0;
height:0;
border-bottom: 50px solid transparent;
border-right:50px solid transparent;
border-top:50px solid yellow;
border-left:50px solid yellow;
float:left;
background: white;
}
.diamond_css3{
overflow: hidden;
width:200px;
height:100px;
-webkit-transform:skew(-45deg);
-moz-transform:skew(-45deg);
-ms-transform:skew(-45deg);
transform:skew(-45deg);
}
.diamond_css3 span{
display: block;/*inline to block*/
-webkit-transform:skew(45deg);
-moz-transform:skew(45deg);
-ms-transform:skew(45deg);
transform:skew(45deg);
}
.trapezoid{
width:100px;
height:0;
border-bottom:100px solid yellow;
border-left:50px solid transparent;
border-right:50px solid transparent;
}
.concentric_circle{
width: 100px;
height: 100px;
background: red;
/* border:20px solid red;
background: #fff;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
-ms-border-radius:100px;
border-radius: 100px; */
border-radius:50px;
border:20px solid yellow;


}
</style>
<body>
<div class="square">square</div>
<div class="rectangle">rectangle</div>
<div class="circle">circle</div>
<div class="oval">oval</div>
<div class="diamond">
<div class="left_triangle"></div>
<div class="square">diamond</div>
<div class="right_triangle"></div>
</div>
<div class="diamond_css3"><span>diamond by css3</span></div>
<div class="trapezoid"><span>梯形</span></div>
<div class="concentric_circle">同心圆</div>
</body>
</html>