标签:border 提示框 content otto alt attr title == pos
<div class="triangle">
</div>
.triangle {
width: 100px;
height: 100px;
border-left: 10px solid #7d7b7b;
border-top: 10px solid #5851c3;
border-right: 10px solid #21a4d6;
border-bottom: 10px solid #4ed621;
box-sizing: border-box;
}
–>结果:
改变{width:0; height:0}
–>
–>再去掉border-top
—>
–>可以看见上面的一半已经没有了
–>设置左右两边border-color:transparent;
–>
–>就得到了想要的三角形了,这是向上的,想要哪边就画哪边的border,并且让它相邻两边的border-color:transparent
–>代码
.triangle {
width: 0;
height: 0;
border-left: 10px solid transparent;
/*border-top: 10px solid #5851c3;*/
border-right: 10px solid transparent;
border-bottom: 10px solid #4ed621;
box-sizing: border-box;
}
如图:
–>
.triangle {
position: relative;
width: 100px;
height: 50px;
border: 2px solid #4ed621;
border-radius: 5px;
}
.triangle:before {
position: absolute;
content: "";
top: -10px;
left: 25px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #4ed621;
}
/* 白色覆盖*/
.triangle:after {
position: absolute;
content: "";
/*减少两像素*/
top: -8px;
left: 25px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #fff;
}
<div class="triangle"></div>
结果:
–> –>