【问题标题】:Chrome not rendering SVG as exptectedChrome 未按预期呈现 SVG
【发布时间】:2021-03-12 05:56:44
【问题描述】:

我在渲染 SVG 图像时遇到问题,但仅限于 Chrome(版本 87)。它在 Chrome 的早期版本(如 86 版)中确实有效。 它确实像在 Firefox 中那样呈现。 SVG 的 URL 是: https://svgshare.com/i/RuQ.svg

在 Chrome 中,天蓝色圆圈不显示, 在 Firefox 中确实如此。

另外,这是一个简单的 HTML 页面,介绍了我如何使用 SVG。

<!DOCTYPE html>
<html>
  <head> </head>

  <body>
    <img height="50px" width="50px" src="https://svgshare.com/i/RuQ.svg"></img>
  </body>
</html>

对于 SVG 中可能出现的问题有什么想法吗?

【问题讨论】:

  • 向 Chrome 的 bugtracker 报告 chrome 错误。

标签: google-chrome svg


【解决方案1】:

这个 SVG 看起来像是由 Adob​​e Illustrator 制作的。虽然 Robert Longson 在形式上是正确的,这是一个 Chrome 错误,但责任完全归咎于 Adob​​e。

对于文档:这是程序导出到 SVG 的内容。我已经将代码缩短了 ca。 50% 删除未使用的定义:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 43 43">
  <defs>
    <style>
    .cls-3{fill:#040f21;}
    .cls-4{mask:url(#mask-2);}
    .cls-5{fill:url(#linear-gradient);}
    .cls-7{filter:url(#luminosity-noclip-2);}
    </style>
    <filter id="luminosity-noclip-2" x="2.36" y="-16315" width="39.63" height="32766" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
      <feFlood flood-color="#fff" result="bg"/>
      <feBlend in="SourceGraphic" in2="bg"/>
    </filter>
    <mask id="mask-2" x="2.36" y="-16315" width="39.63" height="32766" maskUnits="userSpaceOnUse">
      <g class="cls-7"/>
    </mask>
    <linearGradient id="linear-gradient" x1="22.17" y1="60.87" x2="22.17" y2="-17.54" gradientUnits="userSpaceOnUse">
      <stop offset="0.21" stop-color="#3f97f5"/>
      <stop offset="0.83" stop-color="#3fa9f5"/>
    </linearGradient>
  </defs>
  <title>Dlogo</title>
  <g id="Layer_1" data-name="Layer 1">
    <path class="cls-3" d="M28.43,31.83a23.24,23.24,0,0,1-5.41.78c-6.12,0-8.86-2.07-8.86-11.48S17.44,9.44,23.34,9.44a18.52,18.52,0,0,1,5.09.71l-.51,3.28a16.24,16.24,0,0,0-4.22-.61c-3.62,0-5.16,1.13-5.16,8.18S20,29.22,23.7,29.22a15.69,15.69,0,0,0,4.22-.67Z"/>
    <g class="cls-4">
      <path class="cls-5" d="M22.17,41.31A19.81,19.81,0,1,1,42,21.5,19.83,19.83,0,0,1,22.17,41.31Zm0-35.21a15.4,15.4,0,1,0,15.4,15.4A15.41,15.41,0,0,0,22.17,6.1Z"/>
    </g>
  </g>
</svg>

第二个path 是.cls-5 组的唯一成员,该组被#mask-2 屏蔽。

此亮度蒙版包含一个空组,使蒙版默认隐藏所有被蒙版的内容。为了解决这个问题,该组使用#luminosity-noclip-2 过滤。过滤器用白色填充用户空间 39.63 x 32766 的区域,然后将组内容(无)复制到顶部。因此,亮度蒙版应填充为白色,使所有蒙版内容可见,完全不变。

简而言之:无用的垃圾。理论上,它什么也没做。在实践中,它浪费了计算资源,并为几乎所有可能不得不咬你的 bug 渲染器提供了机会。

如果这是 Illustrator 现在制作的作品,请将其扔出窗外,不再使用。

一个在所有方面都与预期相同的干净 SVG 看起来像这样:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 43 43">
  <linearGradient id="linear-gradient" x1="22.17" y1="60.87" x2="22.17" y2="-17.54" gradientUnits="userSpaceOnUse">
    <stop offset="0.21" stop-color="#3f97f5"/>
    <stop offset="0.83" stop-color="#3fa9f5"/>
  </linearGradient>
  <title>Dlogo</title>
  <path style="fill:#040f21;" d="M28.43,31.83a23.24,23.24,0,0,1-5.41.78c-6.12,0-8.86-2.07-8.86-11.48S17.44,9.44,23.34,9.44a18.52,18.52,0,0,1,5.09.71l-.51,3.28a16.24,16.24,0,0,0-4.22-.61c-3.62,0-5.16,1.13-5.16,8.18S20,29.22,23.7,29.22a15.69,15.69,0,0,0,4.22-.67Z"/>
  <path style="fill:url(#linear-gradient);" d="M22.17,41.31A19.81,19.81,0,1,1,42,21.5,19.83,19.83,0,0,1,22.17,41.31Zm0-35.21a15.4,15.4,0,1,0,15.4,15.4A15.41,15.41,0,0,0,22.17,6.1Z"/>
</svg>

【讨论】:

    猜你喜欢
    • 2021-12-21
    • 2017-02-23
    • 2018-10-01
    • 2014-09-29
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 2016-12-20
    相关资源
    最近更新 更多