<g>

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

<g> SVG 元素是一個容器,用於組合其他 SVG 元素。

應用於 <g> 元素的變換將應用於其子元素,並且其屬性將被其子元素繼承。它還可以將多個元素組合起來,以便稍後使用 <use> 元素進行引用。

使用語境

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

屬性

此元素僅包含全域性屬性。

DOM 介面

此元素實現了 SVGGElement 介面。

示例

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>

規範

規範
Scalable Vector Graphics (SVG) 2
# GElement

瀏覽器相容性