SVG 渐变必须在 <defs> 标签中进行定义。
渐变是一种从一种颜色到另一种颜色的平滑过渡。另外,可以把多个颜色的过渡应用到同一个元素上。
在 SVG 中,有两种主要的渐变类型:
<linearGradient> 可用来定义 SVG 的线性渐变。
<linearGradient> 标签必须嵌套在 <defs> 的内部。<defs> 标签是 definitions 的缩写,它可对诸如渐变之类的特殊元素进行定义。
线性渐变可被定义为水平、垂直或角形的渐变:
请把下面的代码拷贝到记事本,然后把文件保存为 "linear1.svg"。把此文件放入您的 web 目录:
</>code
- <?xml version="1.0" standalone="no"?>
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
- "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
- <svg width="100%" height="100%" version="1.1"
- xmlns="http://www.w3.org/2000/svg">
- <defs>
- <linearGradient id="orange_red" 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>
- </defs>
- <ellipse cx="200" cy="190" rx="85" ry="55"
- style="fill:url(#orange_red)"/>
- </svg>
</>code
- <?xml version="1.0" standalone="no"?>
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
- "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
- <svg width="100%" height="100%" version="1.1"
- xmlns="http://www.w3.org/2000/svg">
- <defs>
- <linearGradient id="orange_red" x1="0%" y1="0%" x2="0%" y2="100%">
- <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>
- </defs>
- <ellipse cx="200" cy="190" rx="85" ry="55"
- style="fill:url(#orange_red)"/>
- </svg>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛