CSS多边形阴影

时间:2017-04-25 15:16:30

标签: css css3 svg shadow clipping

我正在使用clip-path属性来塑造我的块元素。

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

我想在该元素中添加“阴影”。所以,我尝试过一些技巧,比如:

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

或者...

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

See my test environment on CodePen.

是否可以使用CSS或SVG?

1 个答案:

答案 0 :(得分:4)

正如评论中所说,你需要2个嵌套元素,剪辑的内部和阴影的外部。



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>
&#13;
&#13;
&#13;