如何用CSS反转Wave SVG?

时间:2019-05-16 01:59:03

标签: css svg

我创建了带有背景图像和SVG的英雄横幅,该SVG在图像上叠加了波浪效果。

但是我不知道如何反转这波,我的意思是改变山谷的侧面和峰顶。

<section class="herobanner"></section>

.herobanner {
    height:100vh; 
    background: 
  url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54 54" width="2000" ><path d="M0 48 C30 60 38 40 64 48 L64 64 L0 64 Z"  fill="white" stroke="rgba(255,255,255,1)" stroke-width="2"/></svg>') bottom, 
  url('../images/bg/herobanner3.jpg') center/cover;

}

我尝试更改svg路径中的一些数字,但没有成功。

非常感谢

1 个答案:

答案 0 :(得分:2)

要反转波形,您需要对其进行缩放。例如,您的svg是这样的:

svg{border:1px solid;transform:scale(-1,1)}
<svg viewBox="0 45 64 19" ><path d="M0 48 C30 60 38 40 64 48 L64 64 L0 64 Z"  stroke="red" /></svg>

或者,可以使用表示属性代替CSS,

<svg viewBox="0 45 64 20" ><path transform="scale(-1,1) translate(-64,0)" d="M0 48 C30 60 38 40 64 48 L64 64 L0 64 Z"  stroke="red" /></svg>

您可以将此SVG元素用作背景:

.herobanner {
  border:1px solid;
  height:100vh; 
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 45 64 20'%3E%3Cpath transform='scale(-1,1) translate(-64,0)' d='M0 48 C30 60 38 40 64 48 L64 64 L0 64 Z' stroke='red' /%3E%3C/svg%3E");
  background-repeat:no-repeat;
}
<section class="herobanner"></section>

或者您可以使用CSS转换.herobanner

.herobanner {
  border:1px solid;
  height:100vh; 
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 45 64 20'%3E%3Cpath  d='M0 48 C30 60 38 40 64 48 L64 64 L0 64 Z' stroke='red' /%3E%3C/svg%3E");
  background-repeat:no-repeat;
  transform:scale(-1,1)
  }
<section class="herobanner"></section>