CSS画三角形

115 阅读1分钟
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 0;
            height: 0;
            border-top: 100px solid red;
            border-bottom: 100px solid blue;
            border-right: 200px solid green;
            border-left: 200px solid yellow;
            

效果图

image.png

            border-top-color: transparent;//设置上边框透明
            border-right-color: transparent;//设置右边框透明
            border-left-color: transparent;//设置左边框透明
        }
    </style>
</head>

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f56c0a4e291b4084b6bdc16664c89fcd~tplv-k3u1fbpfcp-watermark.image?)
<body>
    <div id="box"></div>
</body>

</html>

效果图

image.png