Why doesn't this SVG graphic scale in IE9 and 10 (preview)?

旧街凉风 提交于 2019-12-03 00:20:48

IE seems to be mishandling the missing preserveAspectRatio attribute. You can get it to scale in IE by adding preserveAspectRatio="xMinYMin slice" as seen here: http://jsfiddle.net/2UWNe/4/show

However, what IE is showing is not the correct behavior, and thus this change causes other browsers to behave differently than IE. (Microsoft, however, believes that they support preserveAspectRatio.)

I haven't looked deeply at your units or content bounding boxes. What effect are you really trying to achieve?

SVGs don't scale the same way as raster images like JPG, PNG, and GIF which have a clearly defined size.

You will need to resort to hacks to guarantee same display across browsers.

Try this:

<svg width="100%" height="100%" viewBox="0 0 480 360" preserveAspectRatio="xMidYMin slice" style="width: 100%; padding-bottom: 99.99%; height: 1px; overflow: visible; box-sizing: content-box; enable-background:new 0 0 381.1 381.1;" ... >

See Demo

Learn more

The problem is that you are using percentages for height and width, as explained here (http://www.seowarp.com/blog/2011/06/svg-scaling-problems-in-ie9-and-other-browsers/).

If the width and height are either defined as something as useless as 100% or if they aren’t defined at all, these browsers will make a guess as to what the dimensions ought to be based on the points and shapes defined in the body of the SVG file.

Change to width=480 and height=360 and you should be fine.

Another option is to use viewport units. This way your SVG will scale according to the size of the window:

<svg width="100%" height="20vw" viewBox="0 0 150 150"> 
      <rect x="10" y="10" width="150" height="130" fill="#00ff00"/>
</svg>

https://jsfiddle.net/orikon/qy43fb0p/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!