三角形制作

2023-12-25 15:36:50

参考代码:
?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>三角形制作</title>
    <style>
      .triangle1 {
        width: 0;
        height: 0;
        border-top: 50px solid transparent;
        border-left: 50px solid transparent;
        border-right: 50px solid transparent;
        border-bottom: 50px solid red;
        /* transform: rotate(45deg); */
      }
      .triangle2 {
        position: relative;
        width: 100px;
        height: 100px;
      }
      .triangle2::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        border-width: 0px 100px 100px 0px;
        border-style: solid;
        border-color: transparent red transparent transparent;
      }
      .triangle4 {
        width: 100px;
        height: 100px;
        background-color: red;
        clip-path: polygon(0 0, 100% 0, 50% 100%);
      }
    </style>
  </head>
  <body>
    <h2>方法1</h2>
    <div class="triangle1"></div>
    <h2>方法2</h2>
    <div class="triangle2"></div>
    <h2>方法3</h2>
    <div>
      方法1的CSS添加:<br />
      transform: rotate(45deg);
    </div>
    <h2>方法4</h2>
    <div class="triangle4"></div>
  </body>
</html>

文章来源:https://blog.csdn.net/vinglemar/article/details/135200437
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。