与纯css边界的三角形

时间:2014-03-09 20:49:42

标签: html css

我需要构建一个带有边框三角形的提示的消息持有者。我设法建立了提示using two triangles

#triangle-border {
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 0 100px 80px 100px;
    border-color: transparent transparent #edb2b7 transparent;
}
#triangle-content {
    position:absolute;
    top: 20px;    
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 0 100px 80px 100px;
    border-color: transparent transparent #F9EDEF transparent;
}

我相信它可以用一个HTML对象完成,我只是无法弄清楚如何。你能帮忙吗?

我添加了我正在尝试构建的消息容器的示例

enter image description here

1 个答案:

答案 0 :(得分:1)

此处 FIDDLE :after:before被称为伪元素。

<div id="message-holder"></div>

#message-holder {
    margin-top:50px;
    width:300px;
    height:300px;
    background: #F9EDEF;
    position:relative;
    border:1px solid #edb2b7;
}

#message-holder:before,#message-holder:after{
    content:"";
    position:absolute;
    top:-24px;
    left:25px;
    border-bottom:25px solid #f9edef;
    border-left:25px solid transparent;
    border-right:25px solid transparent;
}
#message-holder:before{
    top:-25px;
    border-bottom-color:#edb2b7;
}