Convert px units to percent

Post questions on how to use or achieve an effect in Inkscape.
Anna

Convert px units to percent

Postby Anna » Sat Mar 08, 2008 6:31 am

Hello.

I've just started using Inkscape, I've created an image mostly consisting of bezier curves and I want to export in svg format. I've just realized that I cant make this image resize to a percentage unit in the browser, and that to do this all the units in the image should had been in percentage values.

Is that correct? or can I resize the image as is? If not, is there a way to convert my paths so that they use percentage values, or do I need to create the design all over again?

Tnx

User avatar
sas
Posts: 404
Joined: Sat Oct 06, 2007 5:42 am

Re: Convert px units to percent

Postby sas » Sat Mar 08, 2008 8:29 am

You don't need to make all the units percentage values (which isn't possible anyway, as you can't do it in paths). Instead, you should use a viewBox attribute on the root 'svg' element.

For example, if your image currently has width="300" and height="200", then add viewBox="0 0 300 200" and change the width and height to percentages. The percentages are percentages of whatever region the image is being displayed in, so most of the time it's best to set the width and height attributes to "100%" (or just remove them altogether, as they default to 100% anyway) - this way the image scales to fit the viewing region (subject to maintaining aspect ratio, which I assume is what you want - otherwise you need a slightly more complicated viewBox).

The only way to do this in Inkscape is with the XML editor, as Inkscape currently has very little support for viewBox.

Anna

Re: Convert px units to percent

Postby Anna » Sun Mar 09, 2008 4:47 am

Tnx for your help..

I've done what you've told me but still nothing :( this is what i have in the root "svg" element:

Code: Select all

<svg
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.0"
   width="100%"
   height="100%"
   viewbox="0 0 900 300"
   id="svg2">


Then when i embed it into the page, I use this code (basically i want to add it as a footer in my page, and i want it to stretch to 100% of the width of my page

Code: Select all

<object data="footer.svg" type="image/svg+xml"
width="100%>
</object>


Also when i leave the height undefined, it only shows about the top 100px of the image and cuts off the rest..

any ideas or pointers? :) tnxx!

Anna

Re: Convert px units to percent

Postby Anna » Sun Mar 09, 2008 4:49 am

found it :D viewBox instead of viewbox :) works fine, tnx so much for your help! :mrgreen:

Anna

Re: Convert px units to percent

Postby Anna » Mon Mar 10, 2008 9:04 am

:cry: :cry: still have problems

when i create a page just to test whether it stretches it works just fine. when i try to embed it into my actual page, even though im using the exact same code, it actually shrinks to half its size in firefox.

in internet explorer with the adobe plugin, it stretches fine to 100% of the page, but it leaves a huge white gap at the top and the bottom of the frame :|

this is the code im using:

Code: Select all

<div class="footerBack">
            <object data="imgs/footer.svg" type="image/svg+xml" width="100%" height="100%">Can't display SVG image</object>
</div>


and in css:

Code: Select all

.footerBack {
      position: relative;
      z-index: 1;
      width: 100%;
}


any ideas on how to fix either the internet explorer white space problem or the non-stretching problem in firefox? tnx

User avatar
microUgly
Site Admin
Posts: 2985
Joined: Sat Jun 02, 2007 3:13 pm
Contact:

Re: Convert px units to percent

Postby microUgly » Mon Mar 10, 2008 10:11 am

I don't have time right now to play with this, but if you can post complete code for both the image and HTML I'll be happy to tool around with it when I can.


Return to “Help with using Inkscape”