CSS 三角形

css四色三角实现方法:

1.将 div 的宽、高设置为 0 ,随后设置四个边框属性,即可得到四色三角

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{
            width: 0;
            height: 0;
            border-top: 100px solid red;
            border-right: 100px solid yellow;
            border-bottom: 100px solid blue;
            border-left: 100px solid green;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

效果图:

2.保留想显示一边的颜色,其余设置为透明,可显示三角形:

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{
            width: 0;
            height: 0;
            border: 100px solid transparent;
            border-left-color: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

效果图:

3.不同形状的三角形:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{
            width: 0;
            height: 0;
            border-top: 100px solid transparent;
            border-right: 50px solid red;
            border-bottom: 0 solid blue;
            border-left: 0 solid green;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

效果图:

实际运用

实现京东价格标签:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{
            border: 1px solid red;
            overflow: hidden;
            position: absolute;
        }

        .box span{
            display: block;
            float: left;
            width: 80px;
            height: 25px;
            line-height: 25px;
            text-align: center;
        }

        .box .sl{
            width: 105px;
            background-color: red;
            color: white;
            font-weight: bolder;
            position: relative;
        }

        .box .sl::before{
            content: '';
            width: 0;
            height: 0;
            border-top: 25px solid red;
            border-right: 15px solid white;
            display: block;
            position: absolute;
            right: 0
        }

        .box .sr{
            color: #999;
            font-size: 14px;
            text-decoration: line-through;
        }
    </style>
</head>
<body>
    <div class="box">
        <span class="sl">¥255.00</span>
        <span class="sr">¥448.00</span>
    </div>
</body>
</html>

效果图:

总结:设置不同border的width和color,可实现不同组合

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值