使用CSS3制做网站经常使用的小三角形

如今在前端开发中,常常会看到一些小三角形,如一些导航的下拉菜单,还有一些聊天信息的气泡模式,不少时候咱们都是经过切图片的方法来制做,今天零度给你们分享一个彻底经过css3实现的小三角效果。css

先上html代码:html

<div class="arrow-up">
     <!--向上的三角-->
</div>
<div class="arrow-right">
    <!--向右的三角-->
</div>
<div class="arrow-down">
    <!--向下的三角-->
</div>
<div class="arrow-left">
    <!--向左的三角-->
</div>

我使用了四个div分别展现上下左右四个方向的箭头,下面是css代码:前端

/*箭头向上*/
.arrow-up {
    width:0; 
    height:0; 
    border-left:30px solid transparent;
    border-right:30px solid transparent;
    border-bottom:30px solid #f00;
}

/*箭头向右*/
.arrow-right {
    width:0; 
    height:0; 
    border-top:20px solid transparent;
    border-bottom: 20px solid transparent;
    border-left: 20px solid green;
}
    
 /*箭头向下*/
.arrow-down {
    width:0; 
    height:0; 
    border-left:40px solid transparent;
    border-right:40px solid transparent;
    border-top:40px solid #ccc;
}
    
 /*箭头向左*/
.arrow-left {
    width:0; 
    height:0; 
    border-top:30px solid transparent;
    border-bottom:30px solid transparent; 
    border-right:30px solid #00f; 
}

这样出来的效果就是这样:css3

颜色和大小固然能够随意控制,这样之后咱们就不须要切图了,直接使用css会更简单。spa

相关文章
相关标签/搜索