Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

html - SVG Rendering problem - Firefox cuts off the sibling SVG elements - is there a workaround?

<div>
  <svg id="svg_viewport"
width="800" height="800"
style="background-color: pink"
>
 <svg id="o_1"
   x="10" y="10" width="200" height="200"
   >
   <image href="https://www.1kfa.com/table/img/image.png"
     height="200" width="200"></image>
 </svg>
 <svg id="o_2"
   x="0" y="100" width="100" height="100"
   >
   <rect id="r_2"
     width="100" height="100"
     fill="green"
     ></rect>
 </svg>
  </svg>
</div>
 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think I've found a workaround.

By adding a viewBox, Firefox decides to render it properly. See line 8:

<div>
  <svg id="svg_viewport"
    width="800" height="800"
    style="background-color: pink"
    >
     <svg id="o_1"
       x="10" y="10" width="200" height="200"
       viewBox="0 0 200 200"
       >
       <image href="https://www.1kfa.com/table/img/image.png"
         height="200" width="200"></image>
     </svg>
     <svg id="o_2"
       x="0" y="100" width="100" height="100"
       >
       <rect id="r_2"
         width="100" height="100"
         fill="green"
         ></rect>
     </svg>
  </svg>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...