31

Is it possible to wrap a SVG image inside a border (that is - putting a border from CSS around that image) .

Sergiu
  • 2,340
  • 5
  • 31
  • 54

2 Answers2

43

Draw a <rect> round the image which is fill="none". You can use the stroke of the <rect> as the border.

Robert Longson
  • 110,343
  • 23
  • 240
  • 227
18

Here are some examples, tested in Firefox:

<svg width="100" height="100" style="border:1px solid black">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>

<br><br>

<svg width="300" height="100" style="border:1px solid black">
<rect width="300" height="100" style="fill:rgb(110, 50, 25); stroke-width:4; stroke:rgb(43, 222, 221);" />
</svg>

<br><br>

<svg width="170" height="170" style="border:1px solid black">
<rect x="10" y="10" width="150" height="150" style="fill:blue; stroke:pink; stroke-width:5; fill-opacity:0.1; stroke-opacity:0.9;" />
</svg>

Hope it helps. :)

Pedro Figueiredo
  • 387
  • 3
  • 13