html - SVGs not scaling properly in IE - has extra space -


i decided switch svg symbols 1 of projects - need them responsive. main idea not have multiple http requests, thinking of merging svgs 1 svg, define symbols , use them follows:

<svg style="display:none;"> <defs> <symbol id="mys">     <path fill-rule="evenodd" clip-rule="evenodd" fill="#3f77bc" d="m222.1,77.7h-10.3c0.1-0.8,0.2-1.4,0.2-2.3         c0-8.5-6.9-15.4-15.4-15.4c-8.5,0-15.4,6.9-15.4,15.4c0,0.9,0.1,1.5,0.2,2.3h-9.3v4h-24.9v-5.2h89.4c0-0.3,0-0.6,0-0.9         c89.4,67.1,82.5,60,74,60s-15.4,6.9-15.4,15.4c0,0.3,0,0.6,0,0.9h-6.2v60.7h4.3l5.3-5.3h22.8l74.3,44.9l-13.5-3.6l0.5-1.7         l-16.5-4.4c-0.3,0.1-0.7,0.2-1,0.2l0,21.4h2v7.2c0,0-2,0.6-1.9,1.3c0.1,0.7,4.1,2.6,3.4,5.5c-0.6,2.9-1.6,4.8-4.4,4.5         c-2.7-0.3-3.4-1.4-3.4-2.6c-0.1-1.2,0-3,0-3l38,67.9c0,0,2-0.5,2.6,1.1c0.6,1.5-0.2,2.7,0.6,3.5c0.8,0.8,4.1,1.4,4.1-1.1         c0-2.5-0.5-2.4-2.1-3.6c-1.7-1.2-3.4-2.8-3.4-3.3c0-0.5-0.1-7.7-0.1-7.7h2.1l0-21.7c-1.4-0.7-2.5-2.1-2.5-3.8         c0-2.3,1.9-4.2,4.2-4.2c2,0,3.6,1.4,4.1,3.2l15.3,4.1l0.4-1.6l55.8,15.1h28.1c0,0,0-23.5,0-26.2c0-2.7,2.1-2.6,2.1-2.6         s32.5-0.5,35.1,0.5c2.7,1,3.3,3.7,3.3,3.7h-2l5,11.6c0,0,7.3,4.6,17.6,7.6c10.3,3,13.6,7.6,13.6,7.6l-1,17.6l1.3,2v77.7z          m81.5,46.8l8.6,8.6h9.3l2.9-2.9l81.5,46.8z m175.5,25l-17.4-0.1v12.6h9.6l2.7,2.7h6.6l175.5,25z m183,23.7h-4c0,0,2,6.6,3,9.9         s0.9,4.2,2.7,4.2c1.9,0,4.2,0,4.2,0l183,23.7z m74.2,63.8c6.8,0,12.3,5.5,12.3,12.3s81,88.4,74.2,88.4c-6.8,0-12.3-5.5-12.3-12.3         s67.4,63.8,74.2,63.8z m196.6,63.8c6.8,0,12.3,5.5,12.3,12.3s-5.5,12.3-12.3,12.3s-12.3-5.5-12.3-12.3s189.8,63.8,196.6,63.8z"/> </symbol> </defs> </svg> <div style="position:relative;width:100%;background:blue;">   <svg class="mys" viewbox="0 0 254 108" preserveaspectratio="xmaxymax meet" style="width:100%;">     <use xlink:href="#mys"></use>   <svg> </div> 

here jsfiddle, check different behaviour in ie (i checked 11 read 9 has multiple issues well): http://jsfiddle.net/ws472q71/

for life of me can't work properly. above code works correctly in firefox , chrome, fails in ie. read ie issues, couldn't find works.

what doing wrong?

is there other similar solution can merge svgs 1 file , use them responsive images?

thanks!

as have discovered, ie has bug doesn't scale svg if don't provide both width , height.

to working in ie, can use trick discovered (?) nicolas gallagher.

http://nicolasgallagher.com/canvas-fix-svg-scaling-in-internet-explorer/

the trick uses <canvas> element. ie does scale canvas elements. if place 1 in <div> svg, svg end correct size. need give canvas same aspect ratio svg.

<div style="position:relative;width:100%;background:blue;">   <canvas width="254" height="108"></canvas>   <svg class="mys" viewbox="0 0 254 108" preserveaspectratio="xmaxymax meet">     <use xlink:href="#mys"></use>   </svg> </div> 

with css

canvas {     display: block;     width: 100%;     visibility: hidden; }  svg {     position: absolute;     top: 0;     left: 0;     width: 100%; } 

canvas {      display: block;      width: 100%;      visibility: hidden;  }    svg {      position: absolute;      top: 0;      left: 0;      width: 100%;  }
<svg style="display:none;">  <defs>  <symbol id="mys">      <path fill-rule="evenodd" clip-rule="evenodd" fill="#3f77bc" d="m222.1,77.7h-10.3c0.1-0.8,0.2-1.4,0.2-2.3          c0-8.5-6.9-15.4-15.4-15.4c-8.5,0-15.4,6.9-15.4,15.4c0,0.9,0.1,1.5,0.2,2.3h-9.3v4h-24.9v-5.2h89.4c0-0.3,0-0.6,0-0.9          c89.4,67.1,82.5,60,74,60s-15.4,6.9-15.4,15.4c0,0.3,0,0.6,0,0.9h-6.2v60.7h4.3l5.3-5.3h22.8l74.3,44.9l-13.5-3.6l0.5-1.7          l-16.5-4.4c-0.3,0.1-0.7,0.2-1,0.2l0,21.4h2v7.2c0,0-2,0.6-1.9,1.3c0.1,0.7,4.1,2.6,3.4,5.5c-0.6,2.9-1.6,4.8-4.4,4.5          c-2.7-0.3-3.4-1.4-3.4-2.6c-0.1-1.2,0-3,0-3l38,67.9c0,0,2-0.5,2.6,1.1c0.6,1.5-0.2,2.7,0.6,3.5c0.8,0.8,4.1,1.4,4.1-1.1          c0-2.5-0.5-2.4-2.1-3.6c-1.7-1.2-3.4-2.8-3.4-3.3c0-0.5-0.1-7.7-0.1-7.7h2.1l0-21.7c-1.4-0.7-2.5-2.1-2.5-3.8          c0-2.3,1.9-4.2,4.2-4.2c2,0,3.6,1.4,4.1,3.2l15.3,4.1l0.4-1.6l55.8,15.1h28.1c0,0,0-23.5,0-26.2c0-2.7,2.1-2.6,2.1-2.6          s32.5-0.5,35.1,0.5c2.7,1,3.3,3.7,3.3,3.7h-2l5,11.6c0,0,7.3,4.6,17.6,7.6c10.3,3,13.6,7.6,13.6,7.6l-1,17.6l1.3,2v77.7z           m81.5,46.8l8.6,8.6h9.3l2.9-2.9l81.5,46.8z m175.5,25l-17.4-0.1v12.6h9.6l2.7,2.7h6.6l175.5,25z m183,23.7h-4c0,0,2,6.6,3,9.9          s0.9,4.2,2.7,4.2c1.9,0,4.2,0,4.2,0l183,23.7z m74.2,63.8c6.8,0,12.3,5.5,12.3,12.3s81,88.4,74.2,88.4c-6.8,0-12.3-5.5-12.3-12.3          s67.4,63.8,74.2,63.8z m196.6,63.8c6.8,0,12.3,5.5,12.3,12.3s-5.5,12.3-12.3,12.3s-12.3-5.5-12.3-12.3s189.8,63.8,196.6,63.8z"/>  </symbol>  </defs>  </svg>  <div style="position:relative;width:100%;background:blue;">    <canvas width="254" height="108"></canvas>    <svg class="mys" viewbox="0 0 254 108" preserveaspectratio="xmaxymax meet">      <use xlink:href="#mys"></use>    </svg>  </div>

the trick works whether trying match width or height.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -