-
Notifications
You must be signed in to change notification settings - Fork 5
/
triangle.html
139 lines (129 loc) · 3.65 KB
/
triangle.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>画一个️️三角形</title>
<style>
.triangle-sec{
width:100%;
height:80px;
display:flex;
justify-content: center;
}
.triangle1-wrap {
width: 50px;
height: 50px;
overflow: hidden;
}
.triangle1 {
width: 50px;
height: 50px;
background-color: red;
transform: rotateZ(45deg);
margin-top: 35px;
}
.triangle2 {
width: 0px;
height: 0px;
border-top: solid 50px blue;
border-bottom: solid 50px transparent;
border-left: solid 50px transparent;
border-right: solid 50px transparent;
}
.triangle3-wrap {
width:100px;
height:100px;
position: relative;
overflow:hidden;
}
.triangle3 {
width:50px;
height:50px;
position: absolute;
background-color: teal;
}
.triangle4{
width:50px;
}
.triangle5{
width: 50px;
height:50px;
background-image:linear-gradient(45deg,#fff 50%, #2980B9 0);
}
.triangle6{
width:50px;
height:50px;
position: relative;
overflow:hidden;
}
.triangle6:after{
content: "";
width: 50px;
height: 50px;
background-color:brown;
transform: rotate(45deg);
position: absolute;
left: 35px;
top: 0px;
}
.triangle7{
width:50px;
height:50px;
background-image:url('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602140892677&di=754062cafde7897f9550b7691882b17b&imgtype=0&src=http%3A%2F%2Ftrademark-pics-search.oss-cn-shanghai.aliyuncs.com%2Fsmall%2Ft4517751695000576.jpg');
background-size:100% 100%;
}
.triangle8{
font-size:50px;
color:darkmagenta;
}
</style>
</head>
<body>
<section class="triangle-sec">
<h1>方法一: transform rotateZ</h1>
<div class='triangle1-wrap'>
<div class='triangle1'></div>
</div>
</section>
<section class="triangle-sec">
<h1>方法二:border</h1>
<div class='triangle2'></div>
</section>
<section class="triangle-sec">
<h1>方法三:canvas</h1>
<canvas id='triangle3' width='50' height='50'></canvas>
</section>
<section class="triangle-sec">
<h1>方法四:svg</h1>
<svg class="triangle4">
<path name="三角形" fill="green" d="M50 0 L0 50 L50 50 Z"/>
</svg>
</section>
<section class="triangle-sec">
<h1>方法五:渐变</h1>
<div class="triangle5"></div>
</section>
<section class="triangle-sec">
<h1>方法六:伪类</h1>
<div class="triangle6"></div>
</section>
<section class="triangle-sec">
<h1>方法七:background-image</h1>
<div class="triangle7"></div>
</section>
<section class="triangle-sec">
<h1>方法八:字体icon</h1>
<div class="triangle8">▲</div>
</section>
<script>
const triangle = document.getElementById('triangle3');
const ctx = triangle.getContext('2d');
ctx.beginPath();
ctx.moveTo(50,0);
ctx.lineTo(0,50);
ctx.lineTo(50,50);
ctx.fillStyle='aqua';
ctx.fill();
</script>
</body>
</html>