Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svg rectangle border not drawing properly

Tags:

html

css

svg

Just getting started using svg's.

I am trying to draw a simple rectangle with a border, but it seems like the border is somehow giving me a shadow-like effect. It seems to draw the right and bottom border much thicker than the top and left border. Very weird.

This happens when I do rounded edges and when with normal sharp edges.

Here is the code:

<svg>
    <rect width="30" height="30" rx="5"
        style="fill:rgb(255,255,255);stroke-width:1;stroke:rgb(0,0,0)"/>
</svg>

I've included a PLNKR: http://plnkr.co/edit/HGBTNyjasqzwtguOIbnV

like image 290
Tom O'Brien Avatar asked Aug 29 '15 19:08

Tom O'Brien


1 Answers

Your rectangle is being clipped by the edge of the <svg>. The stroke width makes the rect wider but doesn't automatically adjust its position. Add x="1" and y="1" to your <rect>

<rect x="1" y="1" width="30" height="30" rx="5"
        style="fill:rgb(255,255,255);stroke-width:1;stroke:rgb(0,0,0)"/>
like image 179
Matthew Dunbar Avatar answered Oct 23 '22 16:10

Matthew Dunbar