【发布时间】:2016-06-09 15:15:08
【问题描述】:
允许在 HTML 中嵌入 SVG...
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hmmm....</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="500px" height="100%">
<text>Hello cruel world!</text>
</svg>
</body>
</html>
...反之亦然:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="500px" height="100%">
<foreignObject x="0" y="0" width="100%" height="100%">
<body xmlns="http://www.w3.org/1999/xhtml">
<h1>Goodbye cruel world...</h1>
</body>
</foreignObject>
</svg>
规范say(23.2,第三段)(我引用:)“如果您想将 SVG 嵌入 XHTML 中的 SVG 中的 XHTML 中的 SVG,没关系……”。我想哇,这太深奥了!然后这样做了:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Yeah!</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="500px" height="100%">
<foreignObject x="0" y="0" width="100%" height="100%">
<body class="svgbody" xmlns="http://www.w3.org/1999/xhtml">
<h1>And hello again!</h1>
</body>
</foreignObject>
</svg>
</body>
</html>
但所有浏览器都将body标签与HTML5 body标签合并(HTML5 body标签获取svgbody类)...这是fiddle(fullscreen);内联 svg 中没有 body 标签。
我不知道为什么,希望你能帮助我!可以通过将 SVG 放在不同的文件中来解决它,但我不想听到它。为什么它不起作用?
【问题讨论】: