菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

SVG 描边属性


SVG 描边属性

stroke 属性设置绘制在元素周围的线条颜色。

我们将介绍六个 stroke 属性

  • stroke - 设置元素周围线条的颜色
  • stroke-width - 设置元素周围线条的宽度
  • stroke-opacity - 设置元素周围线条的透明度
  • stroke-linecap - 设置线条或开放路径末端的形状
  • stroke-dasharray - 设置线条显示为虚线
  • stroke-linejoin - 设置两条线相交处的角的形状

SVG 描边属性

stroke 属性定义元素的轮廓颜色。

stroke 属性可用于以下 SVG 元素:<circle><ellipse><line><path><polygon><polyline><rect><text><textPath><tref><tspan>

stroke 属性的值可以是颜色名称、rgb 值或十六进制值。

在这里,我们使用 stroke 属性来设置多边形、矩形、圆形和文本的轮廓颜色。

I love SVG! Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg width="600" height="220" xmlns="http://www.w3.org/2000/svg">
  <polygon points="50,10 0,190 100,190" fill="lime" stroke="red" />
  <rect width="150" height="100" x="120" y="50" fill="yellow" stroke="red" />
  <circle r="45" cx="350" cy="100" fill="pink" stroke="blue" />
  <text x="420" y="100" fill="red" stroke="blue">I love SVG!</text>
</svg>
自己动手试一试 »

在这里,我们使用 stroke 属性来定义三条线的颜色

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg height="80" width="300" xmlns="http://www.w3.org/2000/svg">
  <g fill="none">
    <path stroke="red" d="M5 20 l215 0" />
    <path stroke="green" d="M5 40 l215 0" />
    <path stroke="blue" d="M5 60 l215 0" />
  </g>
</svg>
自己动手试一试 »

SVG stroke-width 属性

stroke-width 属性定义描边的宽度。

stroke-width 属性可用于以下 SVG 元素:<circle><ellipse><line><path><polygon><polyline><rect><text><textPath><tref><tspan>

在这里,我们使用 stroke-width 属性来设置多边形、矩形、圆形和文本的轮廓宽度。

I love SVG! Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg width="600" height="220" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,10 10,190 110,190" fill="lime" stroke="red" stroke-width="4" />
  <rect width="150" height="100" x="120" y="50" fill="yellow" stroke="red" stroke-width="4" />
  <circle r="45" cx="350" cy="100" fill="pink" stroke="blue" stroke-width="4" />
  <text x="420" y="100" fill="red" stroke="blue" stroke-width="4">I love SVG!</text>
</svg>
自己动手试一试 »

在这里,我们使用 stroke-width 属性来设置三条线的宽度

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg height="80" width="300" xmlns="http://www.w3.org/2000/svg">
  <g fill="none" stroke="red">
    <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-opacity 属性

stroke-opacity 属性定义描边的透明度。

stroke-opacity 属性可用于以下 SVG 元素:<circle><ellipse><line><path><polygon><polyline><rect><text><textPath><tref><tspan>

stroke-opacity 属性的值范围是从 0 到 1(或 0% 到 100%)。

在这里,我们使用 stroke-opacity 属性来设置多边形、矩形、圆形和文本的轮廓透明度。

I love SVG! Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg width="600" height="220" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,10 10,190 110,190" fill="lime" stroke="red" stroke-width="4" stroke-opacity="0.4" />
  <rect width="150" height="100" x="120" y="50" fill="yellow" stroke="red" stroke-width="4" stroke-opacity="0.4" />
  <circle r="45" cx="350" cy="100" fill="pink" stroke="blue" stroke-width="4" stroke-opacity="0.4" />
  <text x="420" y="100" fill="red" stroke="blue" stroke-width="4" stroke-opacity="0.4">I love SVG!</text>
</svg>
自己动手试一试 »

在这里,我们使用 stroke-opacity 属性来设置三条线的透明度。

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg height="80" width="300" xmlns="http://www.w3.org/2000/svg">
  <g fill="none" stroke="red">
    <path stroke-width="2" stroke-opacity="0.4" d="M5 20 l215 0" />
    <path stroke-width="4" stroke-opacity="0.4" d="M5 40 l215 0" />
    <path stroke-width="6" stroke-opacity="0.4" d="M5 60 l215 0" />
  </g>
</svg>
自己动手试一试 »

SVG stroke-linecap 属性

stroke-linecap 属性定义线条或开放路径的末端类型。

stroke-linecap 属性可用于以下 SVG 元素:<path><polyline><line><text><textPath><tref><tspan>

stroke-linecap 属性的值可以是 "butt"(平头)、"round"(圆头)或 "square"(方头)。

在这里,我们使用 stroke-linecap 属性来为三条线设置不同的末端形状。

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg height="120" width="300" xmlns="http://www.w3.org/2000/svg">
  <g fill="none" stroke="red" stroke-width="16">
    <path stroke-linecap="butt" d="M10 20 l215 0" />
    <path stroke-linecap="round" d="M10 50 l215 0" />
    <path stroke-linecap="square" d="M10 80 l215 0" />
  </g>
</svg>
自己动手试一试 »

SVG stroke-dasharray 属性

stroke-dasharray 属性用于创建虚线。

stroke-dasharray 属性可用于以下 SVG 元素:<circle><ellipse><line><path><polygon><polyline><rect><text><textPath><tref><tspan>

stroke-dasharray 属性的值可以是 "none",或者是一系列由逗号或空格分隔的长度/百分比,用于定义破折号和间隙的长度。

在这里,我们使用 stroke-dasharray 属性创建不同的虚线。

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg height="100" width="400" xmlns="http://www.w3.org/2000/svg">
  <g fill="none" stroke="red" stroke-width="6">
    <path stroke-dasharray="5,5" d="M5 20 l215 0" />
    <path stroke-dasharray="10,10" d="M5 40 l215 0" />
    <path stroke-dasharray="35,10" d="M5 60 l215 0" />
    <path stroke-dasharray="20,10,5,5,5,10" d="M5 80 l215 0" />
  </g>
</svg>
自己动手试一试 »

在这里,我们使用 stroke-dasharray 属性为多边形、矩形和圆形创建不同的虚线轮廓。

Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg width="600" height="220" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,10 10,190 110,190" fill="lime" stroke="red" stroke-width="4" stroke-dasharray="10,5" />
  <rect width="150" height="100" x="120" y="50" fill="yellow" stroke="red" stroke-width="4" stroke-dasharray="10,5" />
  <circle r="45" cx="350" cy="100" fill="pink" stroke="blue" stroke-width="4" stroke-dasharray="10,5" />
</svg>
自己动手试一试 »

SVG stroke-linejoin 属性

stroke-linejoin 属性定义两条线相交处的角的形状。

stroke-linejoin 属性可用于以下 SVG 元素:<path><polygon><polyline><rect><text><textPath><tref><tspan>

stroke-linejoin 属性的值可以是 "arcs"(圆弧)、"bevel"(斜角)、"miter"(斜接)、"miter-clip"(斜接裁剪)或 "round"(圆角)。

在这里,我们使用 stroke-linejoin 属性来创建不同的角形状。

Sorry, your browser does not support inline SVG. Sorry, your browser does not support inline SVG. Sorry, your browser does not support inline SVG.

这是 SVG 代码

示例

<svg width="600" height="230" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,25 10,190 110,190" fill="lime" stroke="red" stroke-width="16" stroke-linejoin="round" />
  <rect width="150" height="100" x="140" y="50" fill="yellow" stroke="red" stroke-width="16" stroke-linejoin="round" />
</svg>

<svg width="600" height="230" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,25 10,190 110,190" fill="lime" stroke="red" stroke-width="16" stroke-linejoin="miter" />
  <rect width="150" height="100" x="140" y="50" fill="yellow" stroke="red" stroke-width="16" stroke-linejoin="miter" />
</svg>

<svg width="600" height="230" xmlns="http://www.w3.org/2000/svg">
  <polygon points="55,25 10,190 110,190" fill="lime" stroke="red" stroke-width="16" stroke-linejoin="bevel" />
  <rect width="150" height="100" x="140" y="50" fill="yellow" stroke="red" stroke-width="16" stroke-linejoin="bevel" />
</svg>
自己动手试一试 »

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持