css border实现三角形

实现过程:

正常的border

<div class="Box"></div>
.Box {
     background: #ddd;
     width: 100px;
     height: 100px;
     border-top: 20px solid yellow;
     border-right: 20px solid red;
     border-bottom: 20px solid black;
     border-left: 20px solid blue;
}

分享图片

高度和宽度减小后的border

分享图片

正常border表现为梯形,当Box的高度和宽度减小至0时,border则为三角形

.Box {
        background: #ddd;
        width: 0;
        border-top: 20px solid yellow;
        border-right: 20px solid red;
        border-bottom: 20px solid black;
        border-left: 20px solid blue;
}

分享图片

接下通过设置其他三个border的背景为透明则可以实现三角形

.Box {
        width: 0;
        border-top: 20px solid yellow;
        border-right: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid transparent;
}

分享图片

.Box {
        width: 0;
        border-top: 20px solid transparent;
        border-right: 20px solid red;
        border-bottom: 20px solid transparent;
        border-left: 20px solid transparent;
}

分享图片

.Box {
        width: 0;
        border-top: 20px solid transparent;
        border-right: 20px solid transparent;
        border-bottom: 20px solid black;
        border-left: 20px solid transparent;
}

分享图片

.Box {
        width: 0;
        border-top: 20px solid transparent;
        border-right: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid blue;
}

分享图片

 

参考:https://www.cnblogs.com/youhong/p/6530575.html

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效