首页 > 解决方案 > svg filter shadow path repair

问题描述

How do I fix the gap between shadows? I would like the shadow to be continuous, not intermittent. Shadow should be in one black line without any spaces

This is my example:

.wave-container {
    position: absolute;
    width: 100%;
    height: 100%;
    color: #fff;
    padding: 8px;
    padding-bottom: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    background-color: #ccc;
}
.wave-container .wave {
    position: absolute;
    right: 0;
    background-size: 160px 50px;
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='60' height='10' fill='%23fff' viewBox='0 0 60 10' version='1.1'><defs><filter id='shadow' x='-10' y='-10' width='15' height='15'><feOffset result='offOut' in='SourceAlpha' dx='0' dy='-1'></feOffset><feGaussianBlur result='blurOut' in='offOut' stdDeviation='1'></feGaussianBlur><feBlend in='SourceGraphic' in2='blurOut' mode='normal'></feBlend>  </filter></defs><path d='M0,5 C25,0 35,10 60,5 v5 H0' filter='url(%23shadow)'/></svg>");
    height: 50px;
    left: -160px;
    
}
.wave-container .wave.w1 {
    bottom: 0;
}
.wave-container .wave.w2 {
    top: 0;
}
<div class="wave-container">
        <div class="wave w1"></div>
        <div class="wave w2"></div>
    </div>

标签: csssvgsvg-filters

解决方案


您看到的不连续性是阴影在到达形状边缘时逐渐消失。

与其在 SVG 的边缘完全结束路径,不如尝试将形状从左边缘和右边缘延伸一点。在下面的示例中,我使用五个单位线段在每一侧将形状扩展得更宽。

.wave-container {
    position: absolute;
    width: 100%;
    height: 100%;
    color: #fff;
    padding: 8px;
    padding-bottom: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    background-color: #ccc;
}
.wave-container .wave {
    position: absolute;
    right: 0;
    background-size: 160px 50px;
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='60' height='10' fill='%23fff' viewBox='0 0 60 10' version='1.1'><defs><filter id='shadow' x='-10' y='-10' width='15' height='15'><feOffset result='offOut' in='SourceAlpha' dx='0' dy='-1'></feOffset><feGaussianBlur result='blurOut' in='offOut' stdDeviation='1'></feGaussianBlur><feBlend in='SourceGraphic' in2='blurOut' mode='normal'></feBlend>  </filter></defs><path d='M-5,5 L0,5 C25,0 35,10 60,5 H 65 v5 H-5' filter='url(%23shadow)'/></svg>");
    height: 50px;
    left: -160px;
    
}
.wave-container .wave.w1 {
    bottom: 0;
}
.wave-container .wave.w2 {
    top: 0;
}
<div class="wave-container">
        <div class="wave w1"></div>
        <div class="wave w2"></div>
    </div>


推荐阅读