侧边栏壁纸
  • 累计撰写 106 篇文章
  • 累计创建 19 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

在HTML中无法显示svg文件的问题

zero
2020-09-16 / 0 评论 / 0 点赞 / 24 阅读 / 1059 字
温馨提示:
本文最后更新于 2024-07-02,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

我有一个文件的代码如下:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400" height="110">
  <rect width="400" height="110" style="fill:rgb(0,0,255);" />
</svg>

如果我从Web浏览器(firefox、chromium)打开该文件,则不会显示矢量图像。相反,文件以XML格式显示:
This XML file does not appear to have any style information associated with it. The document tree is shown below.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<svg width="400" height="110">
    <rect width="400" height="110" style="fill:rgb(0,0,255);"/>
</svg>

原因出在SVG图中,没有加入:

<svg width="400" height="110" xmlns="http://www.w3.org/2000/svg">
    <rect width="400" height="110" style="fill:rgb(0,0,255);"/>
</svg>

0

评论区