# 纯css画一个三角形

demo (opens new window)

# 画个三角形

/* 方案一 */
 .triangle {
      width: 0px;
      height: 0px;
      border-top: 100px solid transparent;
      border-bottom: 100px solid red;
      border-left: 100px solid transparent;
      border-right: 100px solid transparent;
  }

/* 方案二: */
  #triangle1::before{
    content: " ";
    display: inline-block;
    border-width: 40px 20px 0px;
    border-style: solid;
    border-color: orange transparent transparent;
    width: 40px;
}
  
<div class="triangle"></div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 画个梯形

/* 方案一: */
.ladderShaped {
   display: inline-block;
    border-width: 40px 20px 0px;
    border-style: solid;
    border-color: orange transparent transparent;
    width: 60px;
}
/* 方案二: */
.ladderShaped1 {
  overflow: hidden;
  height: 30px;

   &::before{
    content: " ";
    display: inline-block;
    border-width: 40px 20px 0px;
    border-style: solid;
    border-color: orange transparent transparent;
    width: 40px;
  }
}

/* 方案三: */
.ladderShaped2 {

   &::before{
    content: " ";
    display: inline-block;
    border-width: 40px 20px 0px;
    border-style: solid;
    border-color: orange transparent transparent;
    width: 60px;
  }
<div id='ladderShaped2'></div>
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