在我们看到类似于这样的图片时:

我们一般都会想,哎,这还不简单,用一张图片就可以了。
的确,用图片可以很轻松地做到。不过我们接下来要讨论的是:
如何用css也作出这样的效果。
首先,我们来定义一个div:
<div class="up"></div>
然后给它增加一些样式:
.up{
width: 50px;
height: 50px;
background-color: red;
font-size: 0px;
line-height: 0px;
}
结果如图:

好好好,别急,放下你手中的砖头,我们不妨设置一下它的边框。
.up{
width: 50px;
height: 50px;
background-color: red;
border:50px solid green;
font-size: 0px;
line-height: 0px;
}
然后就变成这样:

好的好的,别急,我说最后一句:
我们尝试着把它的四个边框的颜色改成不一样。
.up{
width: 50px;
height: 50px;
background-color: red;
border-top: 50px solid green;
border-right: 50px solid yellow;
border-bottom: 50px solid blue;
border-left:50px solid black;
font-size: 0px;
line-height: 0px;
}
结果如下:

好的,别急,我们再尝试着把div的宽度和高度都设置为0;
.up{
width: 0px;
height: 0px;
background-color: red;
border-top: 50px solid green;
border-right: 50px solid yellow;
border-bottom: 50px solid blue;
border-left:50px solid black;
font-size: 0px;
line-height: 0px;
}
结果:

好的,我们得到了四个三角形,
现在,我们要得到方向指向上的那个蓝色的三角形,所以我们把其他三角形的背景颜色设置成透明的,并且去掉之前设置的背景颜色:
.up{
width: 0px;
height: 0px;
border-top: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid blue;
border-left:50px solid transparent;
font-size: 0px;
line-height: 0px;
}

我知道你想说什么,我们仔细观察,发现其实上边框是不必要的,因为它不影响我们下面的那个三角形的大小和形状,所以我们去掉上边框,然后再调整一下背景颜色:
.up{
width: 0px;
height: 0px;
border-right: 50px solid transparent;
border-left:50px solid transparent;
border-bottom: 50px solid #6699cc;
font-size: 0px;
line-height: 0px;
}

完成了。
按照这种方法,我们可以制作四个方向上的三角形:
完整的代码:
html:
<div class="up"></div>
<div class="right"></div>
<div class="down"></div>
<div class="left"></div>
css:
.up,.right,.down,.left{
width: 0px;
height: 0px;
font-size: 0px;
line-height: 0px;
}
.up{
border-right: 50px solid transparent;
border-left:50px solid transparent;
border-bottom: 50px solid #6699cc;
}
.right{
border-bottom: 50px solid transparent;
border-top:50px solid transparent;
border-left: 50px solid green;
}
.down{
border-top: 50px solid yellow;
border-right:50px solid transparent;
border-left: 50px solid transparent;
}
.left{
border-right: 50px solid red;
border-top:50px solid transparent;
border-bottom: 50px solid transparent;
}
完整的效果图:
