问题
下面省略号的<radialGradient>
不会在基于Chrome的浏览器中显示,但会显示其他内容。而萤火虫会同时出现。
我读了这一页和这一页,他们提供了线索,表明这是一个径向梯度问题,但我没有像第一页那样处理任何外部文件,也没有像另一页那样尝试锥形梯度。
目标
我只想让我的第一个<svg>
标签严格用于<defs>
,这样我以后就可以参考零件来减少文件大小,并保持它的整洁。为了消除空白,我在第一个<svg>
标签中添加了style="display: none;"
。
我尝试了什么
一旦我完成了以上操作,我就会添加我的其他<svg>
的(电子邮件、短信等)来多次引用它们。同样,带有defs的第一个空白svg不会显示(这很好),并且<path>
、省略号等在Firefox中显示良好,但在Chrome中不会。
只有当我从第一个svg中去掉style="display: none;"
时,省略号才会在Chrome中显示,即使它们在同一个元素中。
当我注意到这可能是一个<radialGradient>
问题时,我将fill:yellow;stroke:purple;stroke-width:2
添加到我的椭圆样式属性中,这使得椭圆以该样式显示,所以我知道椭圆在那里,但渐变不会在里面显示。
有人知道为什么<radialGradient>
不会出现在基于Chrome的浏览器中,而style="display: none;"
在第一个svg上吗???或者有人有什么办法可以更有效地解决这个问题吗???我知道我可以把所有东西都放在一个svg中,但我需要把它们都分开,这样我就可以更容易地用css进行样式设置,因为它们都是图标。
谢谢!
<!DOCTYPE html>
<html>
<body>
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
style="display:none;"
>
<defs>
<symbol id="ellipsesymbol" viewBox="0 0 126 76">
<radialGradient id="_Radial1" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(62.5,0,0,37.5,62.5069,37.5066)">
<stop offset="0" style="stop-color:#000;stop-opacity:0.5"/>
<stop offset="0.62" style="stop-color:#170725;stop-opacity:0.58"/>
<stop offset="0.82" style="stop-color:#4e187f;stop-opacity:0.78"/>
<stop offset="1" style="stop-color:#8a2be2;stop-opacity:1"/>
</radialGradient>
<ellipse cx="62.5" cy="37.839" rx="62.5" ry="37.5" style="fill:url(#_Radial1);" />
</symbol>
<symbol id="emailsymbol" viewBox="0 0 126 76">
<path
d="M31.15,17.125l0,40.763l62.713,0l0,-40.763l-62.713,-0Zm36.687,24.928c-1.411,1.411 -3.292,2.195 -5.33,2.195c-2.038,0 -3.92,-0.784 -5.331,-2.195l-21.792,-21.792l54.089,-0l-21.636,21.792Zm-17.402,-4.546l-16.149,16.148l0,-32.297l16.149,16.149Zm1.097,1.097l4.547,4.547c1.724,1.724 4.076,2.665 6.428,2.665c2.508,0 4.703,-0.941 6.428,-2.665l4.547,-4.547l16.148,16.149l-54.246,-0l16.148,-16.149Zm23.047,-1.097l16.149,-16.149l-0,32.454l-16.149,-16.305Z"
style="fill:#00bfff;fill-rule:nonzero;"/>
</symbol>
<symbol id="SMSsymbol" viewBox="0 0 126 76">
<path d="M98.587,27.064c0,-4.29 -3.483,-7.773 -7.773,-7.773l-56.464,0c-4.29,0 -7.773,3.483 -7.773,7.773l0,15.546c0,4.29 3.483,7.773 7.773,7.773l15.631,0l-9.002,13.326l19.803,-13.326l30.032,0c4.29,0 7.773,-3.483 7.773,-7.773l0,-15.546Z"
style="fill:#00bfff;"/>
<text x="36.276px" y="42.521px" style="font-family:'KnightsTemplar', 'Knights Templar';font-size:25.665px;">SMS</text>
</symbol>
<!-- .... -->
</defs>
</svg>
<svg id="emailgroup">
<use xlink:href="#ellipsesymbol" />
<use xlink:href="#emailsymbol" />
</svg>
<svg id="smsgroup">
<use xlink:href="#ellipsesymbol" />
<use xlink:href="#SMSsymbol" />
</svg>
<!-- more svg's.... -->
</body>
</html>
您可以用width="0" height="0"
隐藏第一个SVG,而不是display:none
。然后它在Chrome中工作:
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<defs>
<symbol id="ellipsesymbol" viewBox="0 0 126 76">
<radialGradient id="_Radial1" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(62.5,0,0,37.5,62.5069,37.5066)">
<stop offset="0" style="stop-color:#000;stop-opacity:0.5"/>
<stop offset="0.62" style="stop-color:#170725;stop-opacity:0.58"/>
<stop offset="0.82" style="stop-color:#4e187f;stop-opacity:0.78"/>
<stop offset="1" style="stop-color:#8a2be2;stop-opacity:1"/>
</radialGradient>
<ellipse cx="62.5" cy="37.839" rx="62.5" ry="37.5" style="fill:url(#_Radial1);" />
</symbol>
<symbol id="emailsymbol" viewBox="0 0 126 76">
<path d="M31.15,17.125l0,40.763l62.713,0l0,-40.763l-62.713,-0Zm36.687,24.928c-1.411,1.411 -3.292,2.195 -5.33,2.195c-2.038,0 -3.92,-0.784 -5.331,-2.195l-21.792,-21.792l54.089,-0l-21.636,21.792Zm-17.402,-4.546l-16.149,16.148l0,-32.297l16.149,16.149Zm1.097,1.097l4.547,4.547c1.724,1.724 4.076,2.665 6.428,2.665c2.508,0 4.703,-0.941 6.428,-2.665l4.547,-4.547l16.148,16.149l-54.246,-0l16.148,-16.149Zm23.047,-1.097l16.149,-16.149l-0,32.454l-16.149,-16.305Z"
style="fill:#00bfff;fill-rule:nonzero;"/>
</symbol>
<symbol id="SMSsymbol" viewBox="0 0 126 76">
<path d="M98.587,27.064c0,-4.29 -3.483,-7.773 -7.773,-7.773l-56.464,0c-4.29,0 -7.773,3.483 -7.773,7.773l0,15.546c0,4.29 3.483,7.773 7.773,7.773l15.631,0l-9.002,13.326l19.803,-13.326l30.032,0c4.29,0 7.773,-3.483 7.773,-7.773l0,-15.546Z"
style="fill:#00bfff;"/>
<text x="36.276px" y="42.521px" style="font-family:'KnightsTemplar', 'Knights Templar';font-size:25.665px;">SMS</text>
</symbol>
</defs>
</svg>
<svg id="emailgroup">
<use href="#ellipsesymbol" />
<use href="#emailsymbol" />
</svg>
<svg id="smsgroup">
<use href="#ellipsesymbol" />
<use href="#SMSsymbol" />
</svg>
还请注意,xlink:href
已弃用,您现在可以简单地使用href
:
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/href