1

I am trying to create a div with arrow on left and right. No background, only border. Something like this:

enter image description here

I am able to create similar div with filled background color using ::before and ::after tags. However, only borders is something i am not able to achieve. Can it be done with css only?

https://jsfiddle.net/1g16x8p7/1/

html:

<div class="wizard">
  <a class="item">
  </a>
</div>

css:

.item {
    display: inline-block;
    padding: 15px;
    padding-left: 25px;

    /*default styles*/
    background-color: green;
    position: relative;
  }  


 .item:before,
.item:after {
      content: "";
      height: 0;
      width: 0;
      border-width: 15px 0 15px  10px;
      border-style: solid;

      position: absolute;
      left: 100%;
      top: 0;
    }


.item:before {
          border-color: transparent transparent transparent white;
        left: 0;  
      }


.item:after {
        border-color: transparent transparent transparent green;  
      }
3
  • Can you show what you created? With filled background? Commented Oct 31, 2017 at 16:33
  • 1
    The web (HTML) is made of boxes, so no. The best you can do is a transform: skew(45deg); combining 2 divs together. You also got to think of how content will fill that irregular shape. SVG is what you want if you are going to get crazy with shapes. Commented Oct 31, 2017 at 16:35
  • @blackandorangecat Added JSFiddle. Commented Oct 31, 2017 at 16:43

1 Answer 1

6

You can use ::before and ::after with borders on two adjacent sides (e.g. top and right) and then transform: rotate and position: absolute them to create the left and right parts, e.g.

<div class="arrow"></div>

.arrow {
  height: 75px;
  width: 200px;
  border-top: 4px solid black;
  border-bottom: 4px solid black;
  position: relative;
}
.arrow::before, .arrow::after {
  content: "";
  border-top: 4px solid black;
  border-right: 4px solid black;
  height: 55px;
  width: 55px;
  position: absolute;
  transform: rotate(45deg);

}

.arrow::before {
  top: 8px;
  left: -30px;
}

.arrow::after {
  top: 8px;
  right: -30px;
}

Here's an example.

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

1 Comment

Perfect. Thanks! :)

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.