在< rect>上设置笔划宽度:1。 SVG中的元素在矩形的每一边都放置一个笔触。
如何在一个SVG矩形的三边只放一个笔触宽度?
解决方法
如果你需要中风或无中风,那么你也可以使用
stroke-dasharray来做到这一点,通过使破折号和间隙与矩形的边匹配。
- 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,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。