1、线性渐变:
<body>
<svg width="500px" height="300px" style="border: 1px solid">
<defs><!-- 要先定义 -->
<linearGradient id="bg1" x1="0" y1="0" x2="0" y2="100%"><!-- 横向渐变 --><!-- x2=100%:斜着渐变 -->
<stop offset="0%" style="stop-color: rgb(255,255,0);"></stop>
<stop offset="100%" style="stop-color: rgb(255,0,0);"></stop>
</linearGradient>
</defs>
<rect x="100" y="100" height="100" width="200" style="fill:url(#bg1)"></rect>
</svg>
</body>