【发布时间】:2017-06-26 18:37:58
【问题描述】:
我正在尝试为clip-path 六边形添加阴影。
由于通常的box-shadow(和filter:drop-shadow())不适用于clip-path,我试图在下面使用更大的伪元素来伪造效果。
该方法取自here,在一个更简单的示例中运行良好:
body {
background-color: gray;
}
.rectangle {
margin: 10%;
position: absolute;
background: white;
width: 80%;
padding-top: 25%;
}
.rectangle::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
filter: blur(10px) brightness(20%);
transform: scale(1.1);
z-index: -1;
background-color: black;
}
<div class="rectangle">
</div>
但是,对剪辑路径六边形使用完全相同的方法会失败。 这个粗略的草图显示了预期的效果:
相反,我得到:
body {
background-color: gray;
}
.hexagon {
width: 20%;
padding-top: 25%;
-webkit-clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
-webkit-shape-outside: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
position: absolute;
background: rgb(0, 229, 154);
margin: 10%;
}
.hexagon::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(10px) brightness(20%);
transform: scale(2.5);
z-index: -1;
background-color: black;
}
<div class="hexagon">
</div>
两个问题:
- 我怎样才能完成这项工作?
- 为剪辑路径元素伪造阴影的更好方法是什么?
【问题讨论】:
标签: css css-transforms shadow clip-path css-filters