css - 如何在 SVG 标签之间嵌入 html 代码

标签 css html svg vml

我的应用程序是在 VML 中,它允许我在 VML 标签之间嵌入 html。但是 VML 只支持到 IE-8。现在我已经使用 vectorconverter 将 VML 转换为 SVG。但是 SVG 不允许在 SVG 标签之间嵌入 html 标签。在 stackgoogle 上搜索后,我发现使用 foreignobject 标签,但是它也只支持到 IE-8。我还尝试使用 switch 标签放置在异物标签上方,但它没有用。有什么方法可以在下面的 SVG 标签之间嵌入 html 代码。提前致谢

<html>
<head>
<meta charset="UTF-8">
<title>HTML inside SVG</title>
<style type="text/css"></style></head>
<body>        
    <svg width="500" height="300" style="border:1px red solid">
        <switch>
        <foreignobject class="node" x="46" y="22" width="100" height="100">

                <div style="border:1px green solid">I'm a div inside a SVG.</div>                
        </foreignobject>
        </switch>
    </svg>
    <div>Interesting! But you a Foreign Object.</div>
</body>

最佳答案

您可以仅使用 CSS 实现此目的。请参阅随附的 jsFiddle。我已将您的示例留在 html/css 实现上方以供引用。

https://jsfiddle.net/Lwtb9w5s/

<div class="container">
  <div class="inner">
    <span>I'm a div inside a SVG.</span>
  </div>
</div>

.container {
  height: 300px;
  width: 500px;
  border:1px red solid
}

.inner {
  border:1px green solid;
  position: relative;
  top: 22px;
  left: 46px;
  width: 100px;
}

关于css - 如何在 SVG 标签之间嵌入 html 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39791954/

相关文章:

html - Div 在另一个带有一些填充的 div 中

c# - 生成word文档并用html设置方向景观

html - Flexbox 不包装

javascript - D3.js canvas 和 svg 中的 map 缩放行为

html - 使用 col-lg-8 bootstrap 时 margin 自动不起作用

html - 如何从 Bootstrap 列中删除填充和边距?

html - CSS元素的位置

css - 为什么 SVG 不通过 css 背景图像显示

html - 如何填充SVG图像

html - 如何在第一行下方绘制水平分隔线?