HTML 中嵌入的 SVG 中存在大量空白
我将 svg 嵌入到 html 中。
对于嵌入html中的svg,ie&chrome不支持xml:space=preserve。这样多个“ ”就会压缩为一个“ ”。将“”替换为   将保留多个“”并解决问题。
有更好的方法吗?谢谢。请参阅下面的示例 html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
viewBox="0 0 1024 768"
preserveAspectRatio="xMidYMid"
>
<text
x="0"
y="0"
id="textsvg"
font-family="Bitstream Vera Sans"
font-size="100"
fill="black"
>
<tspan
x="0"
dy="100"
>
wel co me vs wel co me
</tspan>
</text>
</svg>
</body>
</html>
I have svg embeded in html.
For svg embeded in html, ie&chrome do not support xml:space=preserve. so multiple " " will condense to one " ". replace " " with   will keep multiple " " and soleve the problem.
Are there any better way to do it? Thank you. please see example html below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
viewBox="0 0 1024 768"
preserveAspectRatio="xMidYMid"
>
<text
x="0"
y="0"
id="textsvg"
font-family="Bitstream Vera Sans"
font-size="100"
fill="black"
>
<tspan
x="0"
dy="100"
>
wel co me vs wel co me
</tspan>
</text>
</svg>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这适用于 Chrome 和 Firefox,但不适用于 IE9:
即使是 SVG-in-XHTML 版本也不适用于 IE9:
This works for me in Chrome and Firefox, but not IE9:
Even the SVG-in-XHTML version doesn't work in IE9:
您可以在文本元素上使用此 css 属性:
text {
空白:前;
}
You can use this css property on the text element :
text {
white-space: pre;
}