使用CSS制作箭头

4
我正在尝试制作类似于水平标签的东西: 但是有一个条件,必须是唯一的div。可能可以使用canvas实现,但我更喜欢使用css。
#msg {
   border-bottom: 10px solid transparent;
    border-right: 10px solid red;
    border-top: 10px solid transparent;
    height: 0;
    width: 100px;
   background-color: rgba(0,0,0,.8);     margin-left:20px;
}

enter image description here

demo


请访问 http://cssarrowplease.com/ 查看。 - Vahid Kharazi
1个回答

9
您可以通过一些边框技巧、定位和:before伪元素来实现此操作。 http://jsfiddle.net/VQcyD/
#msg {
    width:100px;
    height:40px;
    background:red;
    margin-left:40px;
    position:relative;

}
#msg:before {
    content:"";
    position:absolute;
    border-bottom: 20px solid transparent;
    border-right: 20px solid red;
    border-top: 20px solid transparent;
    height: 0px;
    width: 0px;
    margin-left:-20px;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接