<g>

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phần tử SVG <g> là một phần tử chứa dùng để nhóm các phần tử SVG khác.

Các phép biến đổi áp dụng cho phần tử <g> sẽ được thực hiện trên các phần tử con của nó, và các thuộc tính của nó được kế thừa bởi các phần tử con. Nó cũng có thể nhóm nhiều phần tử để sau này tham chiếu bằng phần tử <use>.

Ngữ cảnh sử dụng

CategoriesContainer element, Structural element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements
Shape elements
Structural elements
Gradient elements
<a>, <clipPath>, <filter>, <foreignObject>, <image>, <marker>, <mask>, <pattern>, <script>, <style>, <switch>, <text>, <view>

Thuộc tính

Phần tử này chỉ bao gồm các thuộc tính toàn cục.

Giao diện DOM

Phần tử này triển khai giao diện SVGGElement.

Ví dụ

html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Dùng g để kế thừa các thuộc tính trình bày -->
  <g fill="white" stroke="green" stroke-width="5">
    <circle cx="40" cy="40" r="25" />
    <circle cx="60" cy="60" r="25" />
  </g>
</svg>

Thông số kỹ thuật

Specification
Scalable Vector Graphics (SVG) 2
# GElement

Khả năng tương thích trình duyệt