此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

<polygon>

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

* Some parts of this feature may have varying levels of support.

SVG 元素 <polygon> 用于定义由一系列相连直线段组成的闭合图形。最后一个点会与第一个点相连形成封闭形状。

若需要开放形状,请参见 <polyline> 元素。

使用上下文

类别基本形状元素、图形元素、形状元素
允许的内容任意数量、任意顺序的下列元素:
动画元素
描述性元素

属性

points

此属性定义绘制多边形所需的点列表(由 x,y 绝对坐标对组成)。 值类型<number>+;默认值""动画性

pathLength

此属性用于指定路径的总长度,单位为用户单位。 值类型<number>默认值动画性

DOM 接口

此元素实现了 SVGPolygonElement 接口。

示例

html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <!-- 带有默认填充色的多边形示例 -->
  <polygon points="0,100 50,25 50,75 100,0" />

  <!-- 相同多边形形状示例:只有描边且无填充色 -->
  <polygon points="100,100 150,25 150,75 200,0" fill="none" stroke="black" />
</svg>

规范

Specification
Scalable Vector Graphics (SVG) 2
# PolygonElement

浏览器兼容性

参见