g
元素g
是用来组合对象的容器。添加到g
元素上的变换会应用到其所有的子元素上。添加到g
元素的属性会被其所有的子元素继承。此外,g
元素也可以用来定义复杂的对象,之后可以通过<use>
元素来引用它们。
用法
类别 | 容器元素、结构元素 |
---|---|
允许的内容 | 任意数量、任意顺序的下列元素: 动画元素 描述性元素 形状元素 结构化元素 渐变元素 <a> 、<altGlyphDef> 、<clipPath> 、<color-profile> 、<cursor> 、<filter> 、<font> 、<font-face> 、<foreignObject> 、<image> 、<marker> 、<mask> 、<pattern> 、<script> 、<style> 、<switch> 、<text> 、<view> |
示例
<svg width="100%" height="100%" viewBox="0 0 95 50"
xmlns="http://www.w3.org/2000/svg">
<g stroke="green" fill="white" stroke-width="5">
<circle cx="25" cy="25" r="15" />
<circle cx="40" cy="25" r="15" />
<circle cx="55" cy="25" r="15" />
<circle cx="70" cy="25" r="15" />
</g>
</svg>
属性
全局属性
专有属性
没有专有属性。
DOM 接口
该元素实现了 SVGGElement
的所有接口。
浏览器兼容性
BCD tables only load in the browser