gpt4 book ai didi

xml - 如何在 foreignObject 中嵌入 SVG?

转载 作者:数据小太阳 更新时间:2023-10-29 02:27:16 25 4
gpt4 key购买 nike

MDN says :

将不会绘制 foreignObject 中的任何 SVG 元素,除非以递归方式嵌入具有正确 xmlns 属性规范的正确定义的 SVG 子文档。

我已经尝试为所有后续元素设置正确的命名空间,但没有成功。

我想要完成的大致是这样的:

<svg>
<foreignObject>
some html text
<svg width="10" height="10"><rect fill="red" width="10" height="10" /></svg>
</foreignObject>
</svg>

最佳答案

您必须在 foreignObject 中有一个元素,尽管该元素可能有子元素。所以你可以这样做......

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<foreignObject width="100%" height="100%">
<div xmlns="http://www.w3.org/1999/xhtml">some html text
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect fill="red" width="10" height="10" /></svg>
</div>
</foreignObject>
</svg>

关于xml - 如何在 foreignObject 中嵌入 SVG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11185715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com