本文为在W3Cschool学习后归纳总结,方便系统查看
SVG (Scalable Vector Graphics — 可伸缩矢量图) 是使用 XML 来描述二维图形和绘图程序的语言。SVG文件是纯粹的XML文件,必须用.svg后缀保存文件。
如下SVG文件:
<?xml version="1.0" standalone="no"?> //包含了XML版本的声明,standalon属性表示此文件是否独立(是否引入外部文件)
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> //引入外部SVG DTD,该 DTD 位于 W3C,含有所有允许的 SVG 元素
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg"> //<svg>是根元素,设置了SVG文档的高宽,版本号。xmlns 属性定义 SVG 命名空间
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red"/> //创建圆,cx,cy为圆心坐标,r为半径
</svg>
SVG图形:
<pre name="code" class="html"><?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">
<rect width="300" height="100"
style="fill:rgb(0,0,255);stroke-width:1;
stroke:rgb(0,0,0)"/> //矩形
<ellipse cx="300" cy="150" rx="200" ry="80"
style="fill:rgb(200,100,50);
stroke:rgb(0,0,100);stroke-width:2"/> //椭圆
<line x1="0" y1="200" x2="300" y2="300"
style="stroke:rgb(99,99,99);stroke-width:2"/> //线条
<polygon points="220,100 300,210 170,250"
style="fill:#cccccc;
stroke:#000000;stroke-width:1"/> //折线
<polyline points="5,0 0,20 20,20 20,40 40,40 40,60"
style="fill:blue;stroke:red;stroke-width:2"/> //三角形
<path d="M153 334
C153 334 151 334 151 334
C151 339 153 344 156 344
C164 344 171 339 171 334
C171 322 164 314 156 314
C142 314 131 322 131 334
C131 350 142 364 156 364
C175 364 191 350 191 334
C191 311 175 294 156 294
C131 294 111 311 111 334
C111 361 131 384 156 384
C186 384 211 361 211 334
C211 300 186 274 156 274"
style="fill:white;stroke:red;stroke-width:2"/> //路径(这里画的是个螺旋)
</svg>