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

后端 未结 4 1666
-上瘾入骨i
-上瘾入骨i 2021-02-04 16:56

According to IE website SVG is supported. And according to this answer too What are SVG (Scalable Vector Graphics) supported browsers?

http://jsfiddle.net/jitendravyas/2

相关标签:
4条回答
  • 2021-02-04 17:07

    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?

    0 讨论(0)
  • 2021-02-04 17:18

    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/

    0 讨论(0)
  • 2021-02-04 17:19

    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.

    0 讨论(0)
  • 2021-02-04 17:22

    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

    0 讨论(0)
提交回复
热议问题