我正在使用线性渐变颜色的SVG形状
Content
除了Edge和IE之外,其他地方都可以正常工作,其中形状正确显示,但不是渐变,只有纯色。
由于多种原因(简单使用png后备)我想使用这种实现方式。我没有发现任何关于Edge的这种用法的限制。
这是element.svg
background: url(#{$imgUrlBase}/element.svg);
知道如何在Edge和IE 11中将线性背景的SVG用作背景图像吗?
答案 0 :(得分:3)
IE不喜欢这个SVG。我认为那可能是奇怪的gradientTransform
。
https://jsfiddle.net/efgtu2pj/
如果你摆脱它并更新渐变坐标以进行补偿,它会渲染得很好。
<svg version="1.1" id="l" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 308 308">
<style type="text/css">
.st0{fill:url(#s);}
</style>
<g id="Page-1">
<defs>
<linearGradient id="s" gradientUnits="userSpaceOnUse" x1="308" y1="308" x2="-50" y2="0">
<stop offset="0" style="stop-color:#FF0000"/>
<stop offset="1" style="stop-color:#00FF00"/>
</linearGradient>
</defs>
<path id="shape" class="st0" d="M154,0,308,308,0,308"/>
</g>
</svg>
&#13;
请注意,我使用的坐标并不完全等效。我刚刚选择的值看起来与原始值大致相同。
答案 1 :(得分:0)
这是我从插画家中导出的带有渐变的SVG的示例,然后编辑SVG代码以删除 gradientTransform ,并替换了x1,y1,x2,y2值,以便可在Internet Explorer和Edge中使用:
插画家导出:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="40px" height="150px" viewBox="0 0 40 150" enable-background="new 0 0 40 150" xml:space="preserve">
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="-1023.5181" y1="4587.5352" x2="-1023.2139" y2="4587.5352" gradientTransform="matrix(0 492.7101 -492.7101 0 2260344.5 504297.75)">
<stop offset="0" style="stop-color:#FFCC07"/>
<stop offset="0.5111" style="stop-color:#346966"/>
<stop offset="1" style="stop-color:#51538C"/>
</linearGradient>
<rect fill="url(#SVGID_1_)" width="40" height="150"/>
<path fill="#FFFFFF" d="M20.81,143.313c0.349-0.071,0.677-0.258,0.907-0.564l10.981-14.513c0.504-0.667,0.371-1.625-0.296-2.13
c-0.666-0.504-1.625-0.372-2.13,0.295l-8.354,11.042v-31.681c0-0.835-0.684-1.52-1.521-1.52c-0.835,0-1.52,0.685-1.52,1.52v32.117
L9.674,127.03c-0.541-0.638-1.506-0.717-2.144-0.176c-0.638,0.541-0.716,1.505-0.176,2.143l11.773,13.878
C19.551,143.373,20.229,143.525,20.81,143.313"/>
</svg>
我编辑的代码:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="40px" height="150px" viewBox="0 0 40 150">
<style type="text/css">
.st0{fill:url(#s);}
</style>
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="40" y2="150" >
<stop offset="0" style="stop-color:#FFCC07"/>
<stop offset="0.5111" style="stop-color:#346966"/>
<stop offset="1" style="stop-color:#51538C"/>
</linearGradient>
<rect fill="url(#SVGID_1_)" width="40" height="150"/>
<path fill="#FFFFFF" d="M20.811,143.313c0.349-0.07,0.676-0.258,0.906-0.563l10.981-14.513c0.504-0.668,0.37-1.625-0.296-2.131
c-0.666-0.504-1.625-0.371-2.131,0.295l-8.354,11.043v-31.682c0-0.835-0.684-1.52-1.521-1.52c-0.835,0-1.52,0.685-1.52,1.52v32.117
L9.674,127.03c-0.541-0.638-1.506-0.718-2.144-0.177c-0.638,0.541-0.716,1.506-0.176,2.144l11.773,13.878
C19.551,143.373,20.229,143.525,20.811,143.313"/>
</svg>
此图显示了差异: file diff screenshot