如何用css画三角形

84 阅读1分钟

步骤

  1. 设置一个盒子
  2. 设置四周不同颜色的边框
  3. 将盒子宽高设置为0,仅保留边框
  4. 得到四个三角形,选择其中一个后其他三角形(边框设置颜色为透明)
  5. 将上边框设置为0(去除隐藏部分占据的高度)

ee0b42b0-a279-11eb-ab90-d9ae814b240d.png

2afaa030-a27a-11eb-85f6-6fac77c0c9b3.png

代码代码实现

<style>
  .box{
  /* width: 300px;
    height: 300px; */
  /* background-color: pink; */
  width:0;
  height:0;
  border-top:0px solid transparent;
  border-bottom:50px solid solid green;
  border-left:50px solid transparent;
  border-right:50px solid transparent;
  }
</style>