user1050619
user1050619

Reputation: 20856

Adding arrow to a line or div

I have a div and using that as an arrow. I was able to generate the div but needs to attach a arrow to its top.

div {
  width: 5px;
  height: 220px;
  background-color: red;
  /* Rotate div */
  -ms-transform: rotate(30deg);
  /* IE 9 */
  -webkit-transform: rotate(30deg);
  /* Chrome, Safari, Opera */
  transform: rotate(30deg);
  transform-origin: bottom left;
}
<div>

jsfiddle

https://jsfiddle.net/4j8n45zz/4/

Upvotes: 1

Views: 290

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122037

You can create this with :after pseudo element and just add triangle at top.

div {
  width: 5px;
  height: 220px;
  background-color: red;
  /* Rotate div */
  -ms-transform: rotate(30deg);
  /* IE 9 */
  -webkit-transform: rotate(30deg);
  /* Chrome, Safari, Opera */
  transform: rotate(30deg);
  transform-origin: bottom left;
  position: relative;
}
div:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  border-style: solid;
  transform: translate(-40%, -50%);
  border-width: 0 10px 20px 10px;
  border-color: transparent transparent red transparent;
}
<div></div>

Upvotes: 3

Related Questions