当我在svg:foreignObject
中使用绝对和相对定位来处理HTML对象时,出现了问题。
我创建了这个jsfiddle来演示我的问题。
div.wrapper
应该与svg:g
中的rect
处于同一位置,此
当我在svg:foreignObject
中使用绝对和相对定位来处理HTML对象时,出现了问题。
我创建了这个jsfiddle来演示我的问题。
div.wrapper
应该与svg:g
中的rect
处于同一位置,此
距离这篇文章发布已经有很长时间了,但是这个漏洞仍然存在。
实际上我发现,如果你在 foreignObject
元素中使用 x="50" Y="50"
属性,在Chrome浏览器中它可以按预期工作。
我知道这与 transform
不同,但至少你可以正确地定位你的内容。
<foreignObject width="200px" height="200px">
<div xmlns="http://www.w3.org/1999/xhtml" class="wrapper" style="position: fixed">
<p id="topleft">topleft</p>
<p id="topright">topright</p>
<p id="middle">middle</p>
<p id="bottomleft">bottomleft</p>
<p id="bottomright">bottomright</p>
</div>
</foreignObject>
position: fixed
g
移动到 (0,0),因为translate(50px,50px)
是无效的。请参阅此处的第7.4节:SVG坐标系变换 - swenedo