css写出各种小三角形

本文介绍如何使用纯CSS绘制不同方向的小三角形,并提供了一个实际应用案例。通过简单的边框设置,即可实现美观且灵活的箭头图标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在网页上有些地方,加上小三角形比不加,效果看上去要好好多。现在不用图片也可以弄出小三角,就是用我们的CSS直接写出形状来。如下:

<!DOCTYPE HTML>
<html>
<head>
        <meta charset="UTF-8">
        <title>小三角</title>
        <style type="text/css">
            div{ margin-bottom:20px;}
               /*箭头向上*/
                .arrow-up {
                        width:0; 
                        height:0; 
                        border-left:10px solid transparent;
                        border-right:10px solid transparent;
                        border-bottom:10px solid #000;
                }
                        
                 /*箭头向下*/
                .arrow-down {
                        width:0; 
                        height:0; 
                        border-left:10px solid transparent;
                        border-right:10px solid transparent;
                        border-top:10px solid #000;
                }
                        
                 /*箭头向左*/
                .arrow-left {
                        width:0; 
                        height:0; 
                        border-top:10px solid transparent;
                        border-bottom:10px solid transparent; 
                        border-right:10px solid #000; 
                }
                   
                /*箭头向右*/
                .arrow-right {
                        width:0; 
                        height:0; 
                        border-top:10px solid transparent;
                        border-bottom: 10px solid transparent;
                        border-left: 10px solid #000;
                }
                
                .box{ width:300px; height:300px; background:#838383; position:relative;}
                .box:after{
                    position:absolute;
                        right:-20px;
                        top:10px;
                    display:block;
                        content:"";
                    width:0; 
                        height:0; 
                        border-top:10px solid transparent;
                        border-bottom: 10px solid transparent;
                        border-left: 10px solid #838383;
                }
                
        </style>
</head>
<body>
        
        <div class="arrow-up">
     <!--向上的三角-->
        </div>
        <div class="arrow-down">
                <!--向下的三角-->
        </div>
        <div class="arrow-left">
                <!--向左的三角-->
        </div>
        <div class="arrow-right">
                <!--向右的三角-->
        </div>
        
        <div class="box">
                 :after 伪元素在元素之后添加内容实现小三角
        </div>
        
</body>
</html>

可以根据自己的需要改变大小和颜色,试试吧,还不错的哦。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值