Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding border to SVG image

Tags:

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

like image 218
Sergiu Avatar asked Feb 07 '13 12:02

Sergiu


People also ask

Can you add a border to an SVG?

You can use the stroke of the <rect> as the border. This is the correct answer when it comes to svg:image.

Can you embed CSS in SVG?

There are many Scalable Vector Graphics (SVG), but only certain attributes can be applied as CSS to SVG. Presentation attributes are used to style SVG elements and can be used as CSS properties. Some of these attributes are SVG-only while others are already shared in CSS, such as font-size or opacity .

Can you embed SVG in HTML directly?

SVG images can be written directly into the HTML document using the <svg> </svg> tag. To do this, open the SVG image in VS code or your preferred IDE, copy the code, and paste it inside the <body> element in your HTML document.


2 Answers

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

like image 89
Robert Longson Avatar answered Sep 22 '22 12:09

Robert Longson


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. :)

like image 25
Pedro Figueiredo Avatar answered Sep 20 '22 12:09

Pedro Figueiredo