Demo1:渐变文字
代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Applying a gradient background to text in SVG</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 1200 400">
<defs>
<linearGradient id = "filler" x = "0%" y = "100%">
<stop stop-color = "olivedrab" offset = "0%"/>
<stop stop-color = "peru" offset = "20%"/>
<stop stop-color = "goldenrod" offset = "40%"/>
<stop stop-color = "firebrick" offset = "60%"/>
<stop stop-color = "thistle" offset = "80%"/>
<stop stop-color = "sandybrown" offset = "100%"/>
</linearGradient>
</defs>
<text x="0" y="70%" font-size="180" fill="url(#filler)">S.QW.YA</text>
</svg>
</body>
</html>
效果:
解释:
xmlns="http://www.w3.org/2000/svg" 是XML命名空间,在SVG标签中定义 。
version="1.1" 是SVG命名空间的版本。
viewBox 属性允许指定一个给定的一组图形伸展以适应特定的容器元素。
<svg>
<defs> 引用的元素容器
<linearGradient>
<stop>
<text>
demo2:折线
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>My svg demo</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<polyline points="20,20 40,25 60,40 80,120 120,140 200,180" style="fill:none;stroke:black;stroke-width:3" />
</svg>
</body>
</html>
效果: