使用渐变

时间:2016-05-19 15:50:40

标签: css svg linear-gradients

Wavy shape with gradient

wavy shape

linear gradient

如何将线性渐变和阴影应用于此模式?

<svg viewbox="0 0 60 10">
  <pattern x="-8" id="waves" patternUnits="userSpaceOnUse" width="10" height="10">
    <path d="M0 10 V5 Q2.5 3.5 5 5 T10 5 V10" fill="#FFC338" />
  </pattern>
  <rect x="0" y="0" width="60" height="7" fill="url(#waves)" />
</svg>

3 个答案:

答案 0 :(得分:17)

Paul LeBeau所述,您需要将波浪形状转换为一条路径,然后您可以使用linear gradient填充波浪形状,如下例所示:

<svg viewbox="7.5 0 60 10">
  <defs>
    <linearGradient id="gradient">
      <stop offset="5%" stop-color="#FFC338" />
      <stop offset="95%" stop-color="#FFEA68" />
    </linearGradient>
  </defs>
  <path fill="url(#gradient)" d="M0 10 V5 Q2.5 2.5 5 5 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 t5 0 V10" />
</svg>

答案 1 :(得分:0)

尝试以下方法:

将所有渐变和模式定义放在<defs>块中。 关闭defs块后,放置可见内容标记。

答案 2 :(得分:0)

不完全是您要找的,但请尝试:

<svg viewbox="0 0 100 80">

   <defs>


     <filter id="f1" x="0" y="0" width="140%" height="200%">
        <feOffset result="offOut" in="SourceAlpha" dx="8" dy="6" />
        <feGaussianBlur result="blurOut" in="offOut" stdDeviation="10" />
        <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
     </filter>

    <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
        <stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
        <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
    </linearGradient>

      <pattern x="-8" id="waves" patternUnits="userSpaceOnUse" width="50" height="20">
        <path d="M0 10 V5 Q2.5 3.5 5 5 T10 5 V10" fill="url(#grad1)"   />
      </pattern>

   </defs>

      <rect x="0" y="3" width="200" height="20"  fill="url(#waves)"  filter="url(#f1)" />

</svg>

分别编辑数字参数以查看效果。