利用css制作三角形7.12

文章介绍了如何利用CSS的边框颜色和透明度来创建不同方向的三角形,通过将非所需边框颜色设为透明,调整边框宽度作为三角形的高和底,以及移除不需要的边框,可以生成向左、向右、向上和向下指的三角形。并提供了对应的CSS代码示例和HTML应用方法。
摘要由CSDN通过智能技术生成

三角形的颜色:容器的边框颜色设置三角形的颜色;

三角形的高:容器边框的边框粗细设置三角形的高度;

三角形的底边长:2倍的边框粗细等于三角形的底边长。

原理:容器div两个邻边的边框颜色变透明;对边消失;让产生三角形的div宽高均设置为0;

例:向右指向的三角形。

    .box{

           width:0; height: 0;

           border:solid 20px orange;

           border-top-color: transparent;

           border-bottom-color: transparent;

           border-right: none;

        }

在css中设置三角形:

1、对四个方向指向的三角形进行CSS代码的封装:

      .triangle{ 

           width:0; height:0;

           border:solid 20px #3385ff;

        }

      指向左侧的三角形:

      .triangle-left{ 

           border-top-color: transparent;

           border-bottom-color: transparent;

           border-left: none;

       }

      直向右侧的三角形

     .triangle-right{  

           border-top-color: transparent;

           border-bottom-color: transparent;

           border-right: none;

        }

    指向顶端的三角形

    .triangle-top{

           border-left-color: transparent;

           border-right-color: transparent;

           border-top:none;

        }

      指向低端的三角形

     .triangle-bottom{

           border-left-color: transparent;

           border-right-color: transparent;

           border-bottom: none;

        }

在html中用类名引用:

        <div class="triangle triangle-right"></div>

        <div class="triangle triangle-bottom"></div>

        <div class="triangle triangle-left"></div>

        <div class="triangle triangle-top"></div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值