HTML格式的SVG中的HTML

Spa*_*man 36 html svg

我有一个简单的SVG文件在Firefox中可以正常查看 - 它使用foreignObject包含一些HTML的文本框中的一些包装文本 - 文本包含在div中:

<svg xmlns="http://www.w3.org/2000/svg" width="800" height="500">
<foreignObject class="node" x="46" y="22" width="200" height="300">
<body xmlns="http://www.w3.org/1999/xhtml">
<div>The quick brown fox jumps over the lazy dog. Pack my box with five dozen liquor jugs</div>
</body>
</foreignObject>
</svg>
Run Code Online (Sandbox Code Playgroud)

但是,没有任何数量的调整可以使其作为HTML文档中包含的<svg>元素工作.div总是最终只是与文档中的其他div一起流动.

这基本上是不可能的,或者我在命名空间或其他方面犯了一些错误.但是,任何人都可以将上述SVG包装在HTML文档中并让它在给定位置(相对于SVG或其容器,当然)的给定宽度x高度的框中显示文本吗?

我没有在HTML中看到SVG中的HTML示例,这让我觉得我很愚蠢或者不可能 - 互联网上的例子似乎只是如上所述在SVG中嵌入HTML.我会更深入.

rob*_*rtc 43

对我来说很好:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>HTML in SVG in HTML</title>
  <style type='text/css'>
    svg { border: 1px solid black; }
    svg div { border: 1px dotted blue; }
  </style>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="500">
  <foreignObject class="node" x="46" y="22" width="200" height="300">
    <body xmlns="http://www.w3.org/1999/xhtml">
      <div>The quick brown fox jumps over the lazy dog. Pack my box with
         five dozen liquor jugs</div>
    </body>
  </foreignObject>
</svg>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

  • @Spacedman [这是浏览器支持矩阵](http://caniuse.com/#feat=svg-html5) (2认同)