<g>

<g> SVG 元素是一個用於對其他 SVG 元素進行分組的容器。

應用於 <g> 元素的轉換將對其子元素執行,並且其屬性將由其子元素繼承。它還可以對多個元素進行分組,以便稍後使用 <use> 元素進行引用。

示例

html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Using g to inherit presentation attributes -->
  <g fill="white" stroke="green" stroke-width="5">
    <circle cx="40" cy="40" r="25" />
    <circle cx="60" cy="60" r="25" />
  </g>
</svg>

使用上下文

類別容器元素、結構元素
允許內容任意數量的以下元素,以任意順序
動畫元素
描述性元素
形狀元素
結構元素
漸變元素
<a><clipPath><cursor><filter><font><font-face><foreignObject><image><marker><mask><pattern><script><style><switch><text><view>

規範

規範
可縮放向量圖形 (SVG) 2
# GElement

瀏覽器相容性

BCD 表格僅在瀏覽器中載入