如何在svg中嵌入HTML div

时间:2012-07-08 10:21:42

标签: dom svg

示例:

<div> Hello World </div>

<svg>
<div> From SVG Land</div>
</svg>

问题:

尽管有标签,SVG对象是单独解析而不是dom树的某些适当部分?如何在SVG元素中获取DIV?

2 个答案:

答案 0 :(得分:6)

答案 1 :(得分:1)

如@Stasik所述,可以使用foreignObject。

示例:

<svg>
    <foreignObject width="100" height="50"
               requiredExtensions="http://www.w3.org/1999/xhtml">
      <!-- XHTML content goes here -->
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>Here is a paragraph that requires word wrap</p>
      </body>
    </foreignObject>
<svg>

摘自: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject

相关问题