SVG 線スタイル属性

SVG 線スタイル属性

SVGは幅広い筆跡属性を提供しています。本章では以下の内容について議論します:

  • stroke
  • stroke-width
  • stroke-linecap
  • stroke-dasharray

すべての筆跡属性は、どんな種類の線、テキスト、および要素の輪郭(例えば円)に使用できます。

SVG stroke 属性

stroke 属性は線、テキスト、または要素の輪郭の色を定義します:

これは SVG コードです:

<svg height="80" width="300">
  <g fill="none">
    <path stroke="red" d="M5 20 l215 0" />
    <path stroke="black" d="M5 40 l215 0" />
    <path stroke="blue" d="M5 60 l215 0" />
  </g>
</svg>

自分で試してみる

SVG stroke-width 属性

stroke-width 属性は線、テキスト、または要素の輪郭の太さを定義します:

これは SVG コードです:

<svg height="80" width="300">
  <g fill="none" stroke="black">
    <path stroke-width="2" d="M5 20 l215 0" />
    <path stroke-width="4" d="M5 40 l215 0" />
    <path stroke-width="6" d="M5 60 l215 0" />
  </g>
</svg>

自分で試してみる

SVG stroke-linecap 属性

stroke-linecap 属性は開放したパスの終端の異なるタイプを定義します:

これは SVG コードです:

<svg height="80" width="300">
  <g fill="none" stroke="black" stroke-width="6">
    <path stroke-linecap="butt" d="M5 20 l215 0" />
    <path stroke-linecap="round" d="M5 40 l215 0" />
    <path stroke-linecap="square" d="M5 60 l215 0" />
  </g>
</svg>

自分で試してみる

SVG stroke-dasharray 属性

stroke-dasharray 属性は破線を生成するために使用されます:

これは SVG コードです:

<svg height="80" width="300">
  <g fill="none" stroke="black" stroke-width="4">
    <path stroke-dasharray="5,5" d="M5 20 l215 0" />
    <path stroke-dasharray="10,10" d="M5 40 l215 0" />
    <path stroke-dasharray="20,10,5,5,5,10" d="M5 60 l215 0" />
  </g>
</svg>

自分で試してみる