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.
Figure: The almost finished button.
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de
back to top