XML technologies / SVG / Filters, transformations and gradients / Defining and assigning gradients / Defining and assigning a linear gradient

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The button example still needs an ellipse in the circle’s upper part, filled with a linear gradient. Define linear gradients with the tag <linearGradient>. Name this gradient too with the id attribute. As with radial gradients, specify the starting and final colors using the <stop> tag.

Gradients are normally horizontal, but the attribute gradientTransform can rotate them. All commands available for the transform attribute of the <g> tag can be used. For example, the command rotate rotates by the number of degrees in parentheses, here 90°.

<linearGradient id="linearerVerlauf" gradientTransform="rotate(90)">
  <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
  <stop offset="90%" style="stop-color:rgb(255,1,1);stop-opacity:1"/>
</linearGradient>

Assign this gradient to an ellipse in the circle’s upper part. The necessary code is:

<ellipse cx="200" cy="190" rx="20" ry="12" style="stroke-width:1;stroke:none;fill-opacity:1;opacity:1;fill:url(#linearerVerlauf)"/>

Running the code now produces an almost perfect result. Only the shadow is missing; its creation is explained in Defining shadows and lighting effects with filters.

The almost finished button

Figure: The almost finished button.

   

 

 

 

back to top