2014-10-01 91 views
1

据我所知,通过使用<foreignObject />标签,可以在SVG内添加HTML标签。 我想通过使用iframe内部的SVG加载页面,但它没有工作。我错过了什么吗?或者它不可能使用HTML内部SVG?SVG内部的iframe没有加载

这是我的代码:

<svg xmlns="http://www.w3.org/2000/svg"> 
    <foreignObject x="0" y="0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"> 
     <iframe src="content.html" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> 
    </foreignObject> 
</svg> 

我试图直接从浏览器中加载它,它说明不了什么。

enter image description here

+0

[SVG foreignObject内容不显示,除非纯文本]可能重复(http://stackoverflow.com/questions/13848039/svg-foreignobject-contents-do-not-display-unless-plain-text) – nvl 2014-10-01 07:01:39

回答

2

foreignObject元件需要的宽度和高度属性。它们没有宽度和高度的CSS样式,事实上,您提供的所有CSS都是不适当的,并且会被foreignObject元素忽略。

这应该工作

<svg xmlns="http://www.w3.org/2000/svg"> 
    <foreignObject width="100%" height="100%"> 
     <iframe src="content.html" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> 
    </foreignObject> 
</svg> 

请注意,如果你移动你的iframe之外,其中foreignObject范围使用绝对位置(你不使用IE的不支持foreignObject目前提供的),你正在做的这也可能会给你带来问题。