ویژگی‌های خط SVG

ویژگی‌های خط SVG

SVG ویژگی‌های خطی گسترده‌ای ارائه می‌دهد. در این فصل، ما به بحث در مورد موارد زیر خواهیم پرداخت:

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

همه‌ی ویژگی‌های خطی برای هر نوع خط، متن و لبه‌های عناصر (مانند دایره) قابل استفاده هستند.

ویژگی stroke SVG

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>

آزمایش کنید

ویژگی stroke-width SVG

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>

آزمایش کنید

ویژگی stroke-linecap SVG

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>

آزمایش کنید

ویژگی stroke-dasharray SVG

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>

آزمایش کنید