Sizing SVG in HTML

T

Tom

Is there any way to show a SVG in a HTML in different sizes by changing
the
width and height attributes of the object/embed tag?

Assume a simple SVG like

<svg width="100" height="100">
<rect x="0" y="0" width="100" height="100"
style="fill:none;stroke:black"/>
<svg>

which is embeded in a HTML page like

<object type="image/svg+xml" data="simple.svg"
width="100" height="100">
<embed type="image/svg+xml" src="simple.svg"
width="100" height="100"></embed>
</object>

the SVG is always shown at size 100x100 no matter what I provide for
HTML width and height. Is there anything I can put into my SVG to make
it custom sizable?
I know I could write
<svg width="100%" height="100%">
<rect x="0%" y="0%" width="100%" height="100%"
style="fill:none;stroke:black"/>
<svg>
But that is not ok for me, except for the initial SVG width and height
attributes.

__
Tom
 
J

Joris Gillis

Hi,

Tempore 14:06:28 said:
Is there any way to show a SVG in a HTML in different sizes by changing
the
width and height attributes of the object/embed tag?

I'm not an expert on the topic of SVG, but I'll try to help.

Instead of specifying the width and height on the svg element, specify the viewBox:

<svg viewBox="0 0 100 100">
<rect x="0" y="0" width="100" height="100"
style="fill:none;stroke:black"/>
<svg>

Now you should be able to scale it via HTML syntax.

regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top