CSS 多边形阴影
CSS Polygon Shadow
我正在使用 clip-path
属性 来塑造我的块元素。
clip-path: polygon(0 0, 100% 0, 100% 100px, 50% 100%, 0 100px);
我想在该元素中放置一个 "drop shadow"。所以,我尝试了一些技巧,例如:
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 可以吗?
正如评论中所说,为此您需要 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.</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>
我正在使用 clip-path
属性 来塑造我的块元素。
clip-path: polygon(0 0, 100% 0, 100% 100px, 50% 100%, 0 100px);
我想在该元素中放置一个 "drop shadow"。所以,我尝试了一些技巧,例如:
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 可以吗?
正如评论中所说,为此您需要 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.</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>