现在在前端开发中,经常会看到一些小三角形,如一些导航的下拉菜单,还有一些聊天信息的气泡模式,很多时候我们都是通过切图片的方法来制作,今天零度给大家分享一个完全通过css3实现的小三角效果。
先上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;
}
这样出来的效果就是这样:
颜色和大小当然可以随意控制,这样以后我们就不需要切图了,直接使用css会更简单。