CSS polygon shadow

I use a property clip-pathto form a block element.

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

I would like to add a “shadow” to this element. So, I tried some methods, for example:

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 in CodePen.

Is this possible with CSS or SVG?

+4
source share
1 answer

As mentioned in the comments, for this you need two nested elements: internal for clipping and external for 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.</nav></div>

<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>
Run code
+3
source

Source: https://habr.com/ru/post/1675623/


All Articles