在SVG中,将stroke-width: 1应用于<rect>
元素会在矩形的每个边上放置描边。
那么怎样只在SVG矩形的三个边上放置描边呢?
在SVG中,将stroke-width: 1应用于<rect>
元素会在矩形的每个边上放置描边。
那么怎样只在SVG矩形的三个边上放置描边呢?
rect { fill: none; stroke: black; }
.top { stroke-dasharray: 0,50,150 }
.left { stroke-dasharray: 150,50 }
.bottom { stroke-dasharray: 100,50 }
.right { stroke-dasharray: 50,50,100 }
<svg height="300">
<rect x="0.5" y="0.5" width="50" height="50" class="top"/>
<rect x="0.5" y="60.5" width="50" height="50" class="left"/>
<rect x="0.5" y="120.5" width="50" height="50" class="bottom"/>
<rect x="0.5" y="180.5" width="50" height="50" class="right"/>
</svg>
请查看 jsfiddle。
<rect>
or <polygon>
element, you can use a <path>
or <polyline>
that only covers three sides of the rectangle.<!-- Move to 50,50 then draw a line to 150,50, to 150,150, and then to 50,150 -->
<path d="M50,50 L150,50 150,150 50,150" />
<polyline points="50,50 150,50 150,150 50,150" />
了解更多信息,请阅读关于<polyline>
以及更强大但更令人困惑的<path>
形状。
您可以使用折线来绘制三条描边边,而且完全不需要在矩形上绘制描边。我认为SVG不允许您对路径/形状的不同部分应用不同的描边,因此您需要使用多个对象才能获得相同的效果。
stroke-dasharray
。阅读代码可能有助于您了解其工作原理:https://codepen.io/lazd/pen/WNweNwy?editors=1010 - lazd