SVG <rect>


SVG の形状

SVG には、開発者用に定義された shape 要素があります:

次の章では、矩形から、順次各要素について説明します。


SVG 矩形 - <rect>

例 1

<rect> 要素は、矩形や矩形のバリエーションを作成するために使用します:

Sorry, your browser does not support inline SVG.

SVG コードは次の通りです:

<svg width="400" height="110">
  <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
</svg>
Try it Yourself »

コードの説明:


例 2

次に、いくつかの新しい属性が含まれている別の例を見てみましょう:

Sorry, your browser does not support inline SVG.

SVG コードは次の通りです:

<svg width="400" height="180">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
</svg>
Try it Yourself »

コードの説明:


例 3

要素全体の不透明度を定義します:

Sorry, your browser does not support inline SVG.

SVG コードは次の通りです:

<svg width="400" height="180">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;opacity:0.5" />
</svg>
Try it Yourself »

コードの説明:


例 4

最後の例として、角丸の矩形を作成します:

Sorry, your browser does not support inline SVG.

SVG コードは次の通りです:

<svg width="400" height="180">
  <rect x="50" y="20" rx="20" ry="20" width="150" height="150"
  style="fill:red;stroke:black;stroke-width:5;opacity:0.5" />
</svg>
Try it Yourself »

コードの説明: