Currently building a browser-based SVG application. Within this app, various shapes can be styled and positioned by the user, including rectangles.
When I apply a stroke-width
to an SVG rect
element of say 1px
, the stroke is applied to the rect
’s offset and inset in different ways by different browsers. This is proving to be troublesome, especially when I try to calculate the outer width and visual position of a rectangle and position it next to other elements.
For example:
- Firefox adds 1px inset (bottom and left), and 1px offset (top and right)
- Chrome adds 1px inset (top and left), and 1px offset (bottom and right)
My only solution so far would be to draw the actual borders myself (probably with the path
tool) and position the borders behind the stroked element. But this solution is an unpleasant workaround, and I’d prefer not to go down this road if possible.
So my question is, can you control how an SVG’s stroke-width
is drawn on elements?
paint-order
parameter, where you can specify, that the fill should be rendered on top of the stroke, so you will get the "outside alignment", see jsfiddle.net/hne0kyLg/1 – Melliemelliferouspaint-order
property (SVG 2 implementation seems to be in progress in Chrome). – Stoll