关于svg:svg-常用标签

2次阅读

共计 2398 个字符,预计需要花费 6 分钟才能阅读完成。

1)line:直线

<?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">
 
<line x1="0" y1="0" x2="300" y2="300"
style="stroke:rgb(99,99,99);stroke-width:2"/>
 
</svg>

代码解释:
x1 属性在 x 轴定义线条的开始
y1 属性在 y 轴定义线条的开始
x2 属性在 x 轴定义线条的完结
y2 属性在 y 轴定义线条的完结

2)polyline:折线

<?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">
 
<polyline points="0,0 0,20 20,20 20,40 40,40 40,60"
style="fill:white;stroke:red;stroke-width:2"/>
 
</svg>

3)rect:矩形

<?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 x="20" y="20" rx="20" ry="20" width="250"
height="100" style="fill:red;stroke:black;
stroke-width:5;opacity:0.5"/>
 
</svg>

rect 元素的 width 和 height 属性可定义矩形的高度和宽度
style 属性用来定义 CSS 属性
CSS 的 fill 属性定义矩形的填充色彩(rgb 值、色彩名或者十六进制值)
CSS 的 stroke-width 属性定义矩形边框的宽度
CSS 的 stroke 属性定义矩形边框的色彩

x 属性定义矩形的左侧地位(例如,x=”0″ 定义矩形到浏览器窗口左侧的间隔是 0px)
y 属性定义矩形的顶端地位(例如,y=”0″ 定义矩形到浏览器窗口顶端的间隔是 0px)
CSS 的 fill-opacity 属性定义填充色彩透明度(非法的范畴是:0 – 1)
CSS 的 stroke-opacity 属性定义笔触色彩的透明度(非法的范畴是:0 – 1)

CSS 的 opacity 属性定义整个元素的通明值(非法的范畴是:0 – 1)

rx 和 ry 属性可使矩形产生圆角。

4)circle:圆形

<?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">
 
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red"/>
 
</svg>

cx 和 cy 属性定义圆点的 x 和 y 坐标。如果省略 cx 和 cy,圆的核心会被设置为 (0, 0)

r 属性定义圆的半径。

5)ellipse:椭圆形

<?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">
 
<ellipse cx="300" cy="150" rx="200" ry="80"
style="fill:rgb(200,100,50);
stroke:rgb(0,0,100);stroke-width:2"/>
 
</svg>

cx 属性定义圆点的 x 坐标
cy 属性定义圆点的 y 坐标
rx 属性定义程度半径
ry 属性定义垂直半径

6)polygon:多边形

<?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">
 
<polygon points="220,100 300,210 170,250"
style="fill:#cccccc;
stroke:#000000;stroke-width:1"/>
 
</svg>

points 属性定义多边形每个角的 x 和 y 坐标

正文完
 0