4

我最近学习了如何使用 CSS 和 HTML 创建三角形 div 的外观。现在,我想知道是否可以在三角形 div 的任何边周围添加边框,这样如果我给 div 一个白色背景和黑色边框,你仍然可以看到它吗?有没有办法我可以做到这一点?

JSFIDDLE:http: //jsfiddle.net/c75KM/1/

HTML:

<div class="arrow-up"></div>

CSS:

.arrow-up {
width: 0; 
height: 0; 
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid black;
}
4

1 回答 1

6

这是执行此操作的典型方法:

JSFiddle

.arrow-up:after {
    position:absolute;
    content:"";
    width: 0;
    height: 0;
    margin-top:1px;
    margin-left:2px;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 10px solid white;
}

.arrow-up:before {
    position:absolute;
    content:"";
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 12px solid black;
}
于 2013-02-26T06:51:14.933 回答