SVG <ellipse>

SVG 橢圓 - <ellipse>

<ellipse> 元素用于創建橢圓。

橢圓與圓密切相關。不同之處在于橢圓的 x 和 y 半徑彼此不同,而圓則具有相等的 x 和 y 半徑:

例子 1

下例創建橢圓:

這是 SVG 代碼:

<svg height="140" width="500">
  <ellipse cx="200" cy="80" rx="100" ry="50"
  style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>

親自試一試

代碼解釋:

  • cx 屬性定義橢圓中心的 x 坐標
  • cy 屬性定義橢圓中心的 y 坐標
  • rx 屬性定義水平半徑
  • ry 屬性定義垂直半徑

例子 2

下例創建三個彼此重疊的橢圓:

這是 SVG 代碼:

<svg height="150" width="500">
  <ellipse cx="240" cy="100" rx="220" ry="30" style="fill:purple" />
  <ellipse cx="220" cy="70" rx="190" ry="20" style="fill:lime" />
  <ellipse cx="210" cy="45" rx="170" ry="15" style="fill:yellow" />
</svg>

親自試一試

例子 3

下例組合了兩個橢圓(一黃一白):

這是 SVG 代碼:

<svg height="100" width="500">
  <ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow" />
  <ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white" />
</svg>

親自試一試