css实现三角形和平形四边形

一、三角形

.father {
      width: 0px;
      height: 0px;
      border: 50px solid black;
    }
只设置border
.father {
      width: 0px;
      height: 0px;
      border-top: 50px solid black;
      border-right: 50px solid red;
      border-bottom: 50px solid green;
      border-left: 50px solid blue;
    }
设置四个border
// transparent 关键字表示一个完全透明的颜色,即该颜色看上去将是背景色
.father {
      width: 0px;
      height: 0px;
      border-top: 50px solid black;
      border-right: 50px solid transparent;
      border-bottom: 50px solid transparent;
      border-left: 50px solid transparent;
    }
.caret {
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-top-color: black;
}
三角形
// 节省空间的三角形
.father {
      width: 0px;
      height: 0px;
      border-top: 50px solid black;
      border-left: 50px solid transparent;
      border-right: 50px solid transparent;
    }
节省空间的三角形
// 等腰梯形
.father {
      width: 50px;
      height: 0px;
      border-top: 50px solid black;
      border-left: 50px solid transparent;
      border-right: 50px solid transparent;
    }
等腰梯形
// 中空的图形
.father {
      width: 50px;
      height: 50px;
      border-top: 50px solid black;
      border-right: 50px solid red;
      border-bottom: 50px solid green;
      border-left: 50px solid blue;
    }
中空的图形
// 平形四边形
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <title></title>
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    .father1 {
      position: relative;
      width: 0;
      height: 0;
      border-top: 50px solid black;
      border-right: 50px solid transparent;
      border-bottom: 50px solid transparent;
      border-left: 50px solid transparent;
    }

    .father2 {
      position: absolute;
      top: -50px;
      left: 50px;
      width: 0;
      height: 0;
      border-top: 50px solid transparent;
      border-right: 50px solid transparent;
      border-bottom: 50px solid green;
      border-left: 50px solid transparent;
    }
  </style>
</head>
<body>
  <div class="father1"></div>
  <div class="father2"></div>
</body>

</html>

平形四边形

参考:https://www.jianshu.com/p/1f32120a503b

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容