1

Hi I am trying to create a custom arrow in CSS that looks like the image below.
Ideally I want to create this by overlaying two shapes a triangle and a rectangle (maybe using CSS :after and :before) but I'm not too savvy when it comes to CSS so I have been struggling.I started by just using borders but doesn't look like it is going to work

So far I just have:

.arrow {
  width: 0;
  height: 0;
  border-top: 60px solid transparent;
  border-bottom: 60px solid transparent;
  border-left: 60px solid #ccc;
}
<div class="arrow"></div>

enter image description here

2
  • why not use an image that you can adjust in size, rather then trying to draw an arrow using css? Commented Feb 8, 2017 at 20:01
  • Because I do not want to add it as an image Commented Feb 8, 2017 at 20:01

5 Answers 5

2

Not too hard to make using the :before pseudo element and some transforms:

.container {
   padding: 100px;
}

.arrow {
  display: inline-block;
  height: 150px;
  background: #000;
  width: 75px;
}
.arrow:before {
  content: "";
  border-top: 100px solid #000;
  border-left: 100px solid transparent;
  border-right: 100px solid transparent;
  border-bottom: 100px solid transparent;
  transform: rotateZ(180deg) translateY(100%) translateX(31%);
  position: relative;
  display: inline-block;
}
<div class="container">
  <div class="arrow"></div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

Here's another option.

.arrow{
  width: 0; 
  height: 0; 
  border-top: 60px solid transparent;
  border-bottom: 60px solid transparent;
  border-left: 60px solid #ccc;
  position: relative;
  margin: 0 0 0 100px;
}

.arrow::before{
  content: "";
  height:50px;
  width:80px;
  background: #ccc;
  position: absolute;
  top: 0;
  margin: -100%;
  display: block;
  transform: translateX(-160%) translateY(-50%);
}
<div class="arrow"></div>

Comments

0

Create one rectangle and then add triangle on top with :before pseudo-element and that is it.

.arrow {
  width: 36px;
  height: 50px;
  background: #3F3F3F;
  position: relative;
  margin: 60px;
}
.arrow:before {
  content: '';
  border-style: solid;
  border-width: 0 40px 40px 40px;
  border-color: transparent transparent #3F3F3F transparent;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
}
<div class="arrow"></div>

Comments

0

To explain and demonstrate:

A CSS arrow is created by coloring 1 border side, and then moving the other 3 sides in towards the middle of the shape as transparent so they don't show but cut the remaining colored side into a triangle. The shorthand for this is TOP RIGHT BOTTOM LEFT. So to make a triangle pointing upwards you use the third property or bottom.

Using pseudo elements (incase you want the arrow added to another element) you need content:'' to "create" the pseudo element. I've set them as display: block so that they are in the flow and interact with eachother (rather than being laid on top of one another).

By giving the rectangle position: relative you can then use left: 30px (half of the triangle width) to position it in the middle of the triangle.

.arrowWrapper:before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 60px 60px 60px;
  border-color: transparent transparent black transparent;
  /* border-color: TOP RIGHT BOTTOM LEFT; */
}

.arrowWrapper:after {
  content: '';
  position: relative;
  display: block;
  width: 60px;
  height: 60px;
  background: black;
  left: 30px;
}
<div class="arrowWrapper"></div>

Comments

0

Lifted and modified from http://www.cssportal.com/css3-shapes/:

#eq-triangle {
  width: 0;
  height: 0;
  border-bottom: 104px solid blue;
  border-left: 60px solid transparent;
  border-right: 60px solid transparent;
}

#rectangle {
   width: 40px; 
   height: 80px;
   background: blue;
   margin-left: 40px;
}
<div id="eq-triangle"></div>
<div id="rectangle"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.