-2

I want to make a rectangle with arrows on both sides. I have the jsfiddle http://jsfiddle.net/7wegxh4v/ . Here is my css

<body>
<div id="arrowbox"></div>
</body>



#arrowbox
{
    width: 200px;
    height: 50px;
    background-color:green;
    margin-left:100px;
    margin-top:100px;
}

It now shows a green rectangle. I want to add two equilateral triangle triangles of green color at both ends. How can I do that using css? Any idea?

1 Answers1

4

Try this (using Pseudo-elements):

CSS

#arrowbox
{
    width: 200px;
    height: 50px;
    background-color:green;
    margin-left:100px;
    margin-top:100px;
    position: relative;
}

#arrowbox:after {
    left: 100%;
    top: 50%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-color: rgba(0, 128, 0, 0);
    border-left-color: #008000;
    border-width: 25px;
    margin-top: -25px;
}

#arrowbox:before {
    right: 100%;
    top: 50%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-color: rgba(0, 128, 0, 0);
    border-right-color: #008000;
    border-width: 25px;
    margin-top: -25px;
}

DEMO HERE

Luís P. A.
  • 9,524
  • 2
  • 23
  • 36