1-在元素上画

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.a2{
width: 0;
height: 0;
border-width:10px 20px 30px 40px;
border-color: red blue green yellow;
border-style: solid;
}

.a2{
width: 0;
height: 0;
border-width:30px 30px 30px 30px;
border-color: transparent blue green transparent;
border-style: solid;
}

/* border-width:上 右 下 左 */

2-在:before,:after上画

通常写法如下:

1
2
3
4
5
6
7
8
9
10
content: '';
display: block;
width: 0px;
height: 0px;
border-width: 10px 15px 0px 0;
border-style: solid;
border-color: transparent #ffac00 transparent transparent;
position: absolute;
bottom: 0px;
right: 0px;

具体demo:

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.s0 {
width: 0;
height: 0;
border-width: 10px 20px 30px 40px;
border-color: red blue green yellow;
border-style: solid;
display: inline-block;
}

.s1 {
width: 0;
height: 0;
border-width: 20px 20px 20px 20px;
border-color: red red transparent transparent;
border-style: solid;
display: inline-block;
}

.s2 {
width: 0;
height: 0;
border-width: 20px 10px 20px 30px;
border-color: transparent red transparent transparent;
border-style: solid;
display: inline-block;
}

.s3 {
width: 0;
height: 0;
border-width: 20px 20px 20px 20px;
border-color: transparent red transparent transparent;
border-style: solid;
display: inline-block;
}

.s4 {
width: 0;
height: 0;
border-width: 20px 30px 20px 10px;
border-color: transparent red transparent transparent;
border-style: solid;
display: inline-block;
}

.s5 {
width: 0;
height: 0;
border-width: 20px 40px 20px 0px;
border-color: transparent red transparent transparent;
border-style: solid;
display: inline-block;
}
</style>
</head>

<body>
<div class="s0"></div>
<div class="s1"></div>
<div class="s2"></div>
<div class="s3"></div>
<div class="s4"></div>
<div class="s5"></div>
</body>
</html>