Portions of inline SVG not rendering in Firefox until selected or re-scrolled

huangapple go评论101阅读模式
英文:

Portions of inline SVG not rendering in Firefox until selected or re-scrolled

问题

以下是您提供的内容的中文翻译:

我从网页上导出的一些内联SVG元素来自PlantUML。它们在Chrome、Edge和iOS上的Safari上可以正确显示,但在Firefox中,它们的部分内容有时不会渲染,除非我选择它们或将它们从页面上滚动出去再滚回来。如果我使用<img>标签包含SVG,则不会出现此问题,但这在Safari中无法正确渲染。

SVG具有“width”属性,建议参考这里:https://stackoverflow.com/questions/10353443/rendering-inline-svg-in-firefox

示例:

[![在此输入图像描述][1]][1]

[![在此输入图像描述][2]][2]

  1. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="58px" preserveAspectRatio="none" style="width:105px;height:58px;background:#00000000;" version="1.1" viewBox="0 0 105 58" width="105px" zoomAndPan="magnify">
  2. <defs>
  3. <filter height="300%" id="fd8xeq7sn9ue2" width="300%" x="-1" y="-1">
  4. <feGaussianBlur result="blurOut" stdDeviation="2.0"/>
  5. <feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/>
  6. <feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/>
  7. <feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/>
  8. </filter>
  9. </defs>
  10. <g>
  11. <!--MD5=[3c439da1e0ca43de06b2478d62879606] entity ListDog-->
  12. <g id="elem_ListDog">
  13. <rect fill="#FEFECE" filter="url(#fd8xeq7sn9ue2)" height="37.6094" style="stroke:#000000;stroke-width:1.5;" width="84" x="7" y="7"/>
  14. <text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="64" x="17" y="31.5332">List&lt;Dog&gt;</text>
  15. </g>
  16. </g>
  17. </svg>

这是我用于调整大小并在页面中居中显示的CSS。<svg>元素嵌套在<figure>元素中。

  1. figure.figure {
  2. max-width: 100%;
  3. margin: 1rem auto;
  4. margin: auto;
  5. }
  6. figure.figure svg,
  7. figure.figure img {
  8. display: block;
  9. max-width: 100%;
  10. margin: auto;
  11. height: auto !important;
  12. }

完整的HTML示例:

  1. <figure class="figure">
  2. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  3. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="58px" preserveAspectRatio="none" style="width:105px;height:58px;background:#00000000;" version="1.1" viewBox="0 0 105 58" width="105px" zoomAndPan="magnify">
  4. <defs>
  5. <filter height="300%" id="fd8xeq7sn9ue2" width="300%" x="-1" y="-1">
  6. <feGaussianBlur result="blurOut" stdDeviation="2.0"/>
  7. <feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/>
  8. <feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/>
  9. <feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/>
  10. </filter>
  11. </defs>
  12. <g>
  13. <!--MD5=[3c439da1e0ca43de06b2478d62879606] entity ListDog-->
  14. <g id="elem_ListDog">
  15. <rect fill="#FEFECE" filter="url(#fd8xeq7sn9ue2)" height="37.6094" style="stroke:#000000;stroke-width:1.5;" width="84" x="7" y="7"/>
  16. <text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="64" x="17" y="31.5332">List&lt;Dog&gt;</text>
  17. </g>
  18. </g>
  19. </svg>
  20. <figcaption>
  21. 可能的数据路径
  22. <span class="sources">
  23. <a class="source" href="DataPaths.plantuml" target="_blank" title="点击下载图源代码">(源代码)</a>
  24. <a class="source" href="DataPaths.svg" target="_blank" title="点击下载嵌入式SVG图像">(下载)</a>
  25. </span>
  26. </figcaption>
  27. </figure>

更新:看起来与阴影有关。我使用skinparam Shadowing false去掉了方框上的阴影,问题就解决了。如果可能的话,我宁愿保留阴影,但这是一个线索。

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="449px" preserveAspectRatio="none" style="width:1280px;height:449px;background:#00000000;" version="1.1" viewBox="0 0 1280 449" width="1280px" zoomAndPan="magnify">
  3. <defs/>
  4. <g id="elem_ListDog">
  5. <rect fill="#FEFECE" height="37.6094" style="stroke:#000000;stroke-width:1.5;" width="84" x="521" y="29"/>
  6. <text fill="#000000" font-family="sans-serif" font-size="14"
  7. <details>
  8. <summary>英文:</summary>
  9. I have some inline SVG elements exported from PlantUML on a web page. They display properly in Chrome, Edge, and Safari on iOS, but in Firefox parts of them will sometimes not render until I either select them or scroll them off the page and back on. This also does not occur if I include the SVG using an `&lt;img&gt;` tag, but this doesn&#39;t render properly in Safari.
  10. The SVGs have a &quot;width&quot; attribute, as suggested here: https://stackoverflow.com/questions/10353443/rendering-inline-svg-in-firefox
  11. Example:
  12. [![enter image description here][1]][1]
  13. [![enter image description here][2]][2]
  14. &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; contentStyleType=&quot;text/css&quot; height=&quot;58px&quot; preserveAspectRatio=&quot;none&quot; style=&quot;width:105px;height:58px;background:#00000000;&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 105 58&quot; width=&quot;105px&quot; zoomAndPan=&quot;magnify&quot;&gt;
  15. &lt;defs&gt;
  16. &lt;filter height=&quot;300%&quot; id=&quot;fd8xeq7sn9ue2&quot; width=&quot;300%&quot; x=&quot;-1&quot; y=&quot;-1&quot;&gt;
  17. &lt;feGaussianBlur result=&quot;blurOut&quot; stdDeviation=&quot;2.0&quot;/&gt;
  18. &lt;feColorMatrix in=&quot;blurOut&quot; result=&quot;blurOut2&quot; type=&quot;matrix&quot; values=&quot;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0&quot;/&gt;
  19. &lt;feOffset dx=&quot;4.0&quot; dy=&quot;4.0&quot; in=&quot;blurOut2&quot; result=&quot;blurOut3&quot;/&gt;
  20. &lt;feBlend in=&quot;SourceGraphic&quot; in2=&quot;blurOut3&quot; mode=&quot;normal&quot;/&gt;
  21. &lt;/filter&gt;
  22. &lt;/defs&gt;
  23. &lt;g&gt;
  24. &lt;!--MD5=[3c439da1e0ca43de06b2478d62879606]
  25. entity ListDog--&gt;
  26. &lt;g id=&quot;elem_ListDog&quot;&gt;
  27. &lt;rect fill=&quot;#FEFECE&quot; filter=&quot;url(#fd8xeq7sn9ue2)&quot; height=&quot;37.6094&quot; style=&quot;stroke:#000000;stroke-width:1.5;&quot; width=&quot;84&quot; x=&quot;7&quot; y=&quot;7&quot;/&gt;
  28. &lt;text fill=&quot;#000000&quot; font-family=&quot;sans-serif&quot; font-size=&quot;14&quot; lengthAdjust=&quot;spacing&quot; textLength=&quot;64&quot; x=&quot;17&quot; y=&quot;31.5332&quot;&gt;List&amp;lt;Dog&amp;gt;&lt;/text&gt;
  29. &lt;/g&gt;
  30. &lt;/g&gt;
  31. &lt;/svg&gt;
  32. This is the CSS I am using to resize and center it in the page. The `&lt;svg&gt;` element is embedded within a `&lt;figure&gt;` element.
  33. figure.figure {
  34. max-width: 100%;
  35. margin: 1rem auto;
  36. margin: auto;
  37. }
  38. figure.figure svg,
  39. figure.figure img {
  40. display: block;
  41. max-width: 100%;
  42. margin: auto;
  43. height: auto !important;
  44. }
  45. Full HTML sample:
  46. &lt;figure class=&quot;figure&quot;&gt;
  47. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
  48. &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; contentStyleType=&quot;text/css&quot; height=&quot;58px&quot; preserveAspectRatio=&quot;none&quot; style=&quot;width:105px;height:58px;background:#00000000;&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 105 58&quot; width=&quot;105px&quot; zoomAndPan=&quot;magnify&quot;&gt;
  49. &lt;defs&gt;
  50. &lt;filter height=&quot;300%&quot; id=&quot;fd8xeq7sn9ue2&quot; width=&quot;300%&quot; x=&quot;-1&quot; y=&quot;-1&quot;&gt;
  51. &lt;feGaussianBlur result=&quot;blurOut&quot; stdDeviation=&quot;2.0&quot;/&gt;
  52. &lt;feColorMatrix in=&quot;blurOut&quot; result=&quot;blurOut2&quot; type=&quot;matrix&quot; values=&quot;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0&quot;/&gt;
  53. &lt;feOffset dx=&quot;4.0&quot; dy=&quot;4.0&quot; in=&quot;blurOut2&quot; result=&quot;blurOut3&quot;/&gt;
  54. &lt;feBlend in=&quot;SourceGraphic&quot; in2=&quot;blurOut3&quot; mode=&quot;normal&quot;/&gt;
  55. &lt;/filter&gt;
  56. &lt;/defs&gt;
  57. &lt;g&gt;
  58. &lt;!--MD5=[3c439da1e0ca43de06b2478d62879606]
  59. entity ListDog--&gt;
  60. &lt;g id=&quot;elem_ListDog&quot;&gt;
  61. &lt;rect fill=&quot;#FEFECE&quot; filter=&quot;url(#fd8xeq7sn9ue2)&quot; height=&quot;37.6094&quot; style=&quot;stroke:#000000;stroke-width:1.5;&quot; width=&quot;84&quot; x=&quot;7&quot; y=&quot;7&quot;/&gt;
  62. &lt;text fill=&quot;#000000&quot; font-family=&quot;sans-serif&quot; font-size=&quot;14&quot; lengthAdjust=&quot;spacing&quot; textLength=&quot;64&quot; x=&quot;17&quot; y=&quot;31.5332&quot;&gt;List&amp;lt;Dog&amp;gt;&lt;/text&gt;
  63. &lt;/g&gt;
  64. &lt;/g&gt;
  65. &lt;/svg&gt;
  66. &lt;figcaption&gt;
  67. Possible Datapaths
  68. &lt;span class=&quot;sources&quot;&gt;
  69. &lt;a class=&quot;source&quot; href=&quot;DataPaths.plantuml&quot; target=&quot;_blank&quot; title=&quot;Click to download figure source code.&quot;&gt;(Source)&lt;/a&gt;
  70. &lt;a class=&quot;source&quot; href=&quot;DataPaths.svg&quot; target=&quot;_blank&quot; title=&quot;Click to download embedded SVG figure.&quot;&gt;(Download)&lt;/a&gt;
  71. &lt;/span&gt;
  72. &lt;/figcaption&gt;
  73. &lt;/figure&gt;
  74. ---
  75. Update: it appears to be related to shadowing. I removed the shadowing on the box with `skinparam Shadowing false` and the issue went away. I would prefer to keep shadowing if possible, but it&#39;s a lead.
  76. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
  77. &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; contentStyleType=&quot;text/css&quot; height=&quot;449px&quot; preserveAspectRatio=&quot;none&quot; style=&quot;width:1280px;height:449px;background:#00000000;&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 1280 449&quot; width=&quot;1280px&quot; zoomAndPan=&quot;magnify&quot;&gt;
  78. &lt;defs/&gt;
  79. &lt;g id=&quot;elem_ListDog&quot;&gt;
  80. &lt;rect fill=&quot;#FEFECE&quot; height=&quot;37.6094&quot; style=&quot;stroke:#000000;stroke-width:1.5;&quot; width=&quot;84&quot; x=&quot;521&quot; y=&quot;29&quot;/&gt;
  81. &lt;text fill=&quot;#000000&quot; font-family=&quot;sans-serif&quot; font-size=&quot;14&quot; lengthAdjust=&quot;spacing&quot; textLength=&quot;64&quot; x=&quot;531&quot; y=&quot;53.5332&quot;&gt;List&amp;lt;Dog&amp;gt;&lt;/text&gt;
  82. &lt;/g&gt;
  83. &lt;/svg&gt;
  84. [1]: https://i.stack.imgur.com/KEibD.png
  85. [2]: https://i.stack.imgur.com/FOLmj.png
  86. </details>
  87. # 答案1
  88. **得分**: 1
  89. 我无法复现这个问题,但有一点很明显:`<filter>` 元素混合了无单位的数字和百分比来调整滤镜效果区域的大小。理论上,它们应该是等效的,但也许将它们设置成相匹配会有所帮助。尝试将 `x` 和 `y` 属性设置为"-100%",或者将 `width` 和 `height` 设置为"3"。
  90. <details>
  91. <summary>英文:</summary>
  92. While I can&#39;t reproduce the problem, one thing stands out: The `&lt;filter&gt;` element mixes unitless numbers and percentages for sizing the filter effects region. Theoretically [they should be equipotent](https://svgwg.org/svg2-draft/coords.html#ObjectBoundingBoxUnits), but maybe it helps to make them match. Try either setting the `x` and `y` attributes to &quot;-100%&quot;, or the `width` and `height` to &quot;3&quot;.
  93. </details>
  94. # 答案2
  95. **得分**: 0
  96. 这是要翻译的内容:
  97. "我无法重现这个错误,但也许将SVG滤镜替换为CSS滤镜会有帮助:
  98. ```css
  99. rect, ellipse {
  100. filter: drop-shadow(4px 4px 2px #0006);
  101. }
  102. ```"
  103. <details>
  104. <summary>英文:</summary>
  105. I wasn&#39;t able to reproduce this bug, but maybe swapping the SVG filter for a CSS filter helps:
  106. ```css
  107. rect, ellipse {
  108. filter: drop-shadow(4px 4px 2px #0006);
  109. }

huangapple
  • 本文由 发表于 2023年5月22日 23:16:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定