允许在 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>
规范说(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 类)......这就是小提琴(全屏);内联 svg 中没有正文标记。
我不知道为什么,希望你能帮助我!可以通过将 SVG 放在不同的文件中来解决,但我不想听到它。为什么它不起作用?