【发布时间】:2021-05-17 17:03:57
【问题描述】:
我正在尝试使用 wave SVG,并且我在正文中有一个背景图片
但我希望 SVG 填充透明,以便显示主体背景图像
但是当我尝试使其成为fill: transparent 或fill-opacity: 0
它只是隐藏了所有的波形。那么有没有办法将#000000 替换为显示主体背景图像的透明内容?
这是一个示例代码 https://jsfiddle.net/nLt2vu4k/
* {
margin: 0;
padding: 0;
}
body {
background-image: url("https://wallpaperaccess.com/full/5131560.jpg");
}
header {
min-height: 20rem;
background-color: cyan;
position: relative;
}
.shape {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
transform: rotate(180deg);
}
.shape svg {
position: relative;
display: block;
width: calc(128% + 1.3px);
height: 163px;
}
.shape .shape-fill {
fill: #000000;
}
<html>
<body>
<header>
<div class="shape">
<svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
<path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="shape-fill"></path>
</svg>
</div>
</header>
</body>
</html>
感谢您的帮助, 最好的问候。
【问题讨论】:
-
您在黑色 svg 后面有一个背景颜色为青色的标题,因此当您使 svg 透明时,整个标题都会显示出来。你想做什么?您是要遮盖标题,使其具有波浪形并显示猫背景(顶部边缘为波浪形),还是要尝试做其他事情?
-
我只想将波浪形状的#000000 替换为透明(带有青色背景),以便显示猫图像。如果我只放 fill: transparent 它将显示青色背景而不是猫图像。感谢您的回复。
-
形状没有青色背景,但标题有。目前尚不清楚您要在这里实现什么目标。
-
这是我试图解释的一个例子:prnt.sc/131m58d 所以我想把它变成这样。
-
你不能像这样切开另一个元素的背景。也许是一个面具,但即使那样我也不会过于自信。