css实现三角形

 

 1. Border

.triangle { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 14rpx solid red; }

2. transform

.arrow {
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-right: 50px solid red;
  transform: rotate(45deg);
}

3.  :before 和 :after 伪元素

.arrow {
  position: relative;
}
.arrow:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-right: 50px solid red;
}

4. clip-path

.arrow {
  width: 100px;
  height: 100px;
  background-color: red;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

你可能感兴趣的:(css,前端,javascript,html)