SVG: Stroke相关属性

Stroke

svg 提供一些属性来控制绘制描边的方式

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

stroke

stroke:表示描边颜色

stroke-width

stroke-width:表示描边的粗细

<svg>
  <g fill="none">
    <path stroke="red" d="M5 20 l500 0" />
    <path stroke="blue" d="M5 40 l500 0" />
    <path stroke="black" d="M5 60 l500 0" />
  </g>
</svg>
 <svg>
  <g fill="none" stroke="red">
    <path stroke-width="4" d="M5 20 l500 0" />
    <path stroke-width="8" d="M5 40 l500 0" />
    <path stroke-width="12" d="M5 60 l500 0" />
  </g>
</svg>

stroke-linecap

stroke-linecap:控制边框终点的形状
属性有三个值

  • butt:直边结束线段
  • square:会稍微超出实际路径的范围,超出的大小由stroke-width控制
  • round:边框的终点是圆角,圆角的半径也是由stroke-width控制的
<svg>
  <g fill="none" stroke="green" stroke-width="6">
    <path stroke-linecap="butt" d="M5 20 l500 0" />
    <path stroke-linecap="round" d="M5 40 l500 0" />
    <path stroke-linecap="square" d="M5 60 l500 0" />
  </g>
</svg>

在这里插入图片描述

stroke-linejoin

stroke-linejoin:描边转角的表现方式

  • miter:默认值,表示用方形画笔在连接处形成尖角
  • round:用圆角连接,实现平滑效果
  • bevel:连接处会形成一个斜接
 <svg width="160" height="280">
    <polyline points="40 60 80 20 120 60" stroke="black" stroke-width="20" stroke-linecap="butt" fill="none"
      stroke-linejoin="miter" />

    <polyline points="40 140 80 100 120 140" stroke="black" stroke-width="20" stroke-linecap="round" fill="none"
      stroke-linejoin="round" />

    <polyline points="40 220 80 180 120 220" stroke="black" stroke-width="20" stroke-linecap="square" fill="none"
      stroke-linejoin="bevel" />
  </svg>

在这里插入图片描述

stroke-dasharray

stroke-dasharray:表示虚线描边

  • 属性是一组用逗号分割的数字组成的数列
<svg>
  <g fill="none" stroke="black" stroke-width="4">
    <path stroke-dasharray="290" d="M0 0 l290 0" />
    <path stroke-dasharray="5,5" d="M5 20 l290 0" />
    <path stroke-dasharray="10,10" d="M5 40 l290 0" />
    <path stroke-dasharray="20,10,5,5,5,10" d="M5 60 l290 0" />
  </g>
</svg>

在这里插入图片描述

stroke-dashoffset

stroke-dashoffset:表示虚线的起始偏移

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值