【例子】用css的border写三角形

利用border写三角形,这里提供2种方案:

这个盒子的宽高都要先设置成0,用border的值作为宽高

1、先把四周的三角符号都设置成透明,在需要保留的那一个方位设置成有颜色即可,

      缺点:在透明的地方也占了位置,而且得到的三角形只能是等腰三角;

.triangleBox{
    width:0;
    height:0;
    border:100px solid transparent;
    border-right:100px solid #000;
}

2、先把需要设置三角形方位的相邻2个方位设置成透明,需要的那一个方向再设置成有颜色即可,

      缺点:写多一句样式(滑稽脸),

      优点:可以根据需要设置正三角形还是等腰三角形或者非规则三角形,而且透明的方向可以不占位置。

.triangleBox{
    width:0;
    height:0;
    border-top:100px solid transparent;
    border-bottom:100px solid transparent;
    border-right:150px solid #ff3600;
}

发布了22 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_42618289/article/details/103872193