CSS Polygon Shadow
Asked Answered
L

1

6

I'm using the clip-path property to shape my block element.

clip-path: polygon(0 0, 100% 0, 100% 100px, 50% 100%, 0 100px);

I would like to put a "drop shadow" in that element. So, I've tried some techniques, like:

box-shadow: 0 15px 30px 0 rgba(0, 0, 0, 0.5);

Or...

filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.5));

See my test environment on CodePen.

Is it possible with CSS or SVG?

Liquidation answered 25/4, 2017 at 15:16 Comment(5)
The only box-shadow you can have on a clip-path is inset. The normal one is outside the element, hence getting clipped.Jemy
@AndreiGheorghiu, box-shadow kept hidden even using the clip-path: inset(0) (test only).Liquidation
best would be to use an svg or give a try to a gradient codepen.io/anon/pen/BRQzbqJanellejanene
The box-shadow would be inset, @CaioTarifa, not the clip-path. You can always use clip-path on your element while wrapping it inside the same parent with position:relative along with an svg with position:absolute added solely for the purpose of getting the box-shadow effect.Jemy
@AndreiGheorghiu, my bad, you're right. I don't know if I understand, but I'll try.Liquidation
O
8

As it was said in the comments, you need 2 nested elements for this, the inner for the clipping and the outer for the shadow.

body {
  background-color: gray;
}

.navigation {
  filter: drop-shadow(0 15px 30px rgba(0, 0, 200, 0.5));
}

.innernav {
  /* PATH */
  clip-path: polygon(0 0, 100% 0, 100% 100px, 50% 100%, 0 100px);
  
  
  /* OTHERS */
  background-color: silver;
  color: white;
  height: 150px;
  position: fixed;
  text-align: center;
  top: 0;
  width: 100%;
  z-index: 100;
}

.main {
  padding: 200px 20px 0;
  text-align: center;
}
<nav class="navigation"><div class="innernav">Hi, I'm a nav.</div></nav>

<main class="main">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates quia velit modi veniam! Velit fuga facilis blanditiis iure aperiam cumque quasi officia quaerat dignissimos neque repellat quisquam voluptates sequi, hic?</p>
</main>
Outhe answered 25/4, 2017 at 20:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.