CSS设置三角形

1 篇文章 0 订阅

通过设置边框来实现三角形。如下图:
运行后的结果的截图

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>小三角</title>
    <style>
        .demo:after {
            content: '';
            display: inline-block;
            width: 0;
            height: 0;
            border-top: 50px solid red;
            border-right: 50px solid green;
            border-bottom: 50px solid blue;
            border-left: 50px solid yellow;
            position: relative;
            top: 0px;
            left: 30px;
        }
        .top:after {
            content: '';
            width: 0px;
            height: 0px;
            display: inline-block;
            border-top: 50px solid transparent;
            border-right: 50px solid transparent;
            border-bottom: 50px solid blue;
            border-left: 50px solid transparent;
            position: relative;
            top: 10px;
            left: 30px;
        }
        .right:after {
            content: '';
            width: 0px;
            height: 0px;
            display: inline-block;
            border-top: 50px solid transparent;
            border-right: 50px solid transparent;
            border-bottom: 50px solid transparent;
            border-left: 50px solid yellow;
            position: relative;
            top: 40px;
            left: 30px;
        }
        .bottom:after {
            content: '';
            width: 0px;
            height: 0px;
            display: inline-block;
            border-top: 50px solid red;
            border-right: 50px solid transparent;
            border-bottom: 50px solid transparent;
            border-left: 50px solid transparent;
            position: relative;
            top: 80px;
            left: 30px;
        }
        .left:after {
            content: '';
            width: 0px;
            height: 0px;
            display: inline-block;
            border-top: 50px solid transparent;
            border-right: 50px solid green;
            border-bottom: 50px solid transparent;
            border-left: 50px solid transparent;
            position: relative;
            top: 50px;
            left: 0px;
        }
    </style>
</head>
<body>
    <div class="demo">这是一整个边框</div>
    <div class="top">这是一个向上的边框三角形</div>
    <div class="right">这是一个向右的边框三角形</div>
    <div class="bottom">这是一个向下的边框三角形</div>
    <div class="left">这是一个向左的边框三角形</div>
    <div>
        <h2>部分css说明:</h2>
        <h3>content: '';<span>内容为空</span></h3>
        <h3>border-top: 50px solid transparent;<span>设置上边框为透明,其他的同理</span></h3>
    </div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值