SVG参考手册:https://www.runoob.com/svg/svg-reference.html
1 <body> 2 <svg xmlns="http://www.w3.org/2000/svg" height="500px" width="500px" version="1.1"> 3 <circle cx="200" cy="100" r="100" stroke="#afeedd" 4 stroke-width="5" fill="#f0ddff" /> 5 </svg> 6 </body>
height
和 width
属性是设置SVG文档的高宽, version
属性可定义所使用的 SVG 版本, xmlns
属性可定义 SVG 命名空间;cx
和 cy
属性定义圆中心的 x 和 y 坐标,如果忽略这两个属性,那么圆点会被设置为 (0, 0), r
属性定义圆的半径;stroke
和 stroke-width
属性控制如何显示形状的轮廓,fill
属性设置形状内的颜色;1 <body> 2 <svg xmlns="http://www.w3.org/2000/svg" width="500px" height="500px" version="1.1"> 3 <rect x="50" y="100" width="300" height="150" 4 style="fill:rgb(145,245,255);stroke-width:5;stroke:#EE799F;fill-opacity:0.9;stroke-opacity:0.9;"/> 5 </svg> 6 </body>
width
和 height
属性可定义矩形的高度和宽度;style
属性用来定义 CSS 属性fill
属性定义矩形的填充颜色(rgb 值、颜色名或者十六进制值);stroke-width
属性定义矩形边框的宽度;stroke
属性定义矩形边框的颜色;fill-opacity
属性定义填充颜色透明度,取值为0-1;stroke-opacity
属性定义轮廓颜色的透明度,取值为0-1;1 <body> 2 <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px"> 3 <polygon points="100,10 40,180 190,60 10,60 160,180" style="fill:#B4EEB4;stroke:#DB7093 ;stroke-width:3;fill-rule:nonzero;"/> 4 </svg> 5 </body>
<polygon>
标签用来创建含有不少于三个边的图形,也就是多边形,多边形是由直线组成,其形状是"封闭"的;points
属性定义多边形每个角的 x 和 y 坐标,x和y之间用逗号隔开,坐标与坐标之间用空格隔开;fill-rule
属性用于指定使用哪一种算法去判断画布上的某区域是否属于该图形“内部”,它有三个有效值nonzero(非零) 、evenodd(奇偶)、inherit,默认为nonzero;<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="keai" x="0" y="0">
<feGaussianBlur in="SourceGraphic" stdDeviation="10" />
</filter>
</defs>
<rect width="150" height="100" stroke="red" stroke-width="5"
fill="#7EC0EE" filter="url(#keai)" />
</svg>
</body>
<filter>
元素id属性定义一个滤镜的唯一名称;<feGaussianBlur>
元素定义模糊效果;in="SourceGraphic"
这个部分定义了由整个图像创建效果;stdDeviation
属性定义模糊量;<rect>
元素的滤镜属性用来把元素链接到"f1"滤镜,这里是一个矩形;<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px">
<defs>
<filter id="myImg" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="10" dy="10" />
<feColorMatrix result = "matrixOut" in = "offOut" type = "matrix" values = "0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0"/>
<feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="10" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<rect width="200" height="200" stroke="#90EE90" stroke-width="5" fill="#FFEFDB" filter="url(#myImg)" />
</svg>
</body>
<defs>
元素定义短并含有特殊元素(如滤镜)定义;<filter>
标签用来定义SVG滤镜,<filter>标签使用必需的id属性来定义向图形应用哪个滤镜;<feOffset>
元素是用于创建阴影效果;<feColorMatrix>
过滤器是用来转换偏移的图像使之更接近黑色的颜色;<feGaussianBlur>
元素的stdDeviation属性定义了模糊量;<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px">
<defs>
<linearGradient id="yuan" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(238,210,238);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,250,205);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="200" rx="150" ry="80" fill="url(#yuan)" />
</svg>
</body>
<linearGradient>
元素用于定义线性渐变,<linearGradient>标签必须嵌套在<defs>的内部;<linearGradient>
标签的id属性可为渐变定义一个唯一的名称;<linearGradient>
标签的X1,X2,Y1,Y2属性定义渐变开始和结束位置;offset
属性用来定义渐变的开始和结束位置;原文:https://www.cnblogs.com/cnlisiyiii-stu/p/11557377.html