Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make an arrow using CSS

Tags:

html

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

like image 624
user947462 Avatar asked Sep 17 '25 10:09

user947462


1 Answers

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;
}
like image 106
Joseph Marikle Avatar answered Sep 20 '25 01:09

Joseph Marikle