1# svg
2
3基础容器,主要作为svg的根节点使用,也可以在svg中嵌套使用。
4
5
6>  **说明:**
7>  - 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8>
9>  - svg父组件或者svg组件需要定义宽高值,否则不进行绘制。
10
11## 权限列表
12
1314
15
16## 子组件
17
18支持[svg](js-components-svg.md)、[rect](js-components-svg-rect.md)、[circle](js-components-svg-circle.md)、[ellipse](js-components-svg-ellipse.md)、[path](js-components-svg-path.md)、[line](js-components-svg-line.md)、[polygon](js-components-svg-polygon.md)、[polyline](js-components-svg-polyline.md)、[text](js-components-svg-text.md)、[animate](js-components-svg-animate.md)、[animateTransform](js-components-svg-animatetransform.md)。
19
20
21## 属性
22
23支持Svg组件[通用属性](js-components-svg-common-attributes.md)和以下属性,设置的通用属性会传递给子组件。
24
25| 名称      | 类型                                 | 默认值  | 必填   | 描述                                       |
26| ------- | ---------------------------------- | ---- | ---- | ---------------------------------------- |
27| id      | string                             | -    | 否    | 组件的唯一标识。                                 |
28| width   | <length>\|<percentage> | -    | 否    | 设置组件的宽度。                                 |
29| height  | <length>\|<percentage> | -    | 否    | 设置组件的高度。                                 |
30| x       | <length>\|<percentage> | -    | 否    | 设置当前svg的x轴坐标,根svg节点无效。                   |
31| y       | <length>\|<percentage> |      | 否    | 设置当前svg的y轴坐标,根svg节点无效。                   |
32| viewBox | string                             | -    | 否    | 设置当前svg的视口。支持的格式为<number number number number>,4个参数分别表示min-x, min-y, width and height,viewBox的宽高和svg的宽高不一致,会以中心对齐进行缩放。 |
33
34
35## 示例
36
37```html
38<!-- xxx.hml -->
39<div class="container">
40  <svg width="400" height="400">
41    <svg width="200" height="200" viewBox="0 0 100 100">
42      <rect x="10" y="10" width="80" height="80" fill="#00FF00"></rect>
43    </svg>
44    <rect x="10" y="10" width="80" height="80" fill="red" ></rect>
45    <svg x="0" y="0" width="200" height="200" viewBox="0 0 200 200">
46      <rect x="10" y="10" width="80" height="80" fill="red"></rect>
47    </svg>
48    <svg x="0" y="0" width="200" height="200" viewBox="0 0 400 400">
49      <rect x="10" y="10" width="80" height="80" fill="blue"></rect>
50    </svg>
51  </svg>
52</div>
53```
54
55
56![zh-cn_image_0000001173164789](figures/zh-cn_image_0000001173164789.png)
57