Fill an SVG shape with a gradient

后端 未结 3 1094
礼貌的吻别
礼貌的吻别 2021-02-04 08:24

How can I apply Linear gradient and drop shadow to this pattern?

相关标签:
3条回答
  • 2021-02-04 08:55

    not exactly what you are looking for, but try:

    <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>
    

    Edit numerical parameters individually to see the effect.

    0 讨论(0)
  • 2021-02-04 09:07

    As commented by Paul LeBeau, you need to convert the wavy shape to one path, then you can fill the wavy shape with a linear gradient as shown in this example:

    <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>

    0 讨论(0)
  • 2021-02-04 09:11

    Try the following:

    Place all the gradient and pattern definitions within a <defs> block. After the defs block is closed place your visible content tags.

    0 讨论(0)
提交回复
热议问题