css制作三角

使用border属性制作三角:当给一个宽高为0的盒子设置不同颜色的边框时会如下图所示,由此可见,想要设置三角,则可以将其余三条边框设置为透明色

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 三角形的做法 */
        .box1 {
            width: 0;
            height: 0;
            border-top: 50px solid red;
            border-right: 50px solid green;
            border-bottom: 50px solid yellow;
            border-left: 50px solid purple;
            margin: 100px;
        }

        .box2 {
            width: 0;
            height: 0;
            border: 10px solid transparent;
            border-bottom-color: red;
        }
    </style>
</head>

<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>

</html>

posted @ 2023-07-25 15:15  af88  阅读(18)  评论(0)    收藏  举报