Search code examples
htmlcssborderbox-shadow

How to add a box shadow to a css generated arrow?


I'm having difficulty adding a box shadow around the outline of the arrow that was generated using border properties. Is there a way to make the box shadow in the shape the same as the arrow instead of a square box?

Here's a jsfiddle.

enter image description here

HTML:

<a class="bx-prev"></a>
<a class="bx-next"></a>

CSS:

.bx-prev, .bx-next {
  border-right: 15px solid green;
  border-bottom: 15px solid green;
  width: 35px;
  height: 35px;
  top: 200px;
  box-shadow: 0 0 10px 0 rgba(0,0,0,0.5);
}
.bx-prev {
  transform: rotate(135deg);
  position: absolute;
  left: 220px;
}
.bx-next {
  transform: rotate(-45deg);
  position: absolute;
  left: 320px;
}

Solution

  • You can try the blur filter by creating the same arrow with a pseudo element:

    .bx-prev,
    .bx-next {
      top: 200px;
      position:relative;
    }
    
    .bx-prev {
      transform: rotate(135deg);
      position: absolute;
      left: 220px;
    }
    
    .bx-next {
      transform: rotate(-45deg);
      position: absolute;
      left: 320px;
    }
    /*the arrow*/
    .bx-prev:before,
    .bx-next:before,
    .bx-prev:after,
    .bx-next:after{
      content:"";
      position:absolute;
      border-right: 15px solid green;
      border-bottom: 15px solid green;
      width: 35px;
      height: 35px;
    }
    /*the shadow*/
    .bx-prev:after,
    .bx-next:after{
      border-color: red;
      z-index:-1;
      filter:blur(5px);
    }
    <a class="bx-prev"></a>
    <a class="bx-next"></a>