user947462
user947462

Reputation: 949

Make an arrow using CSS

I am trying to make something like an horizontal label: But there is a condition, should be an unique div. Probably with canvas is possible, however i have preference by 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

Upvotes: 4

Views: 6938

Answers (1)

Joseph Marikle
Joseph Marikle

Reputation: 78580

You can accomplish this with some border hacks, positioning, and the :before psudo-element.

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;
}

Upvotes: 9

Related Questions