未定义图像上 href 的 SVG 命名空间前缀 xlink

标签 svg xlink

我有一个 svg 内容,看起来有点像这样:

<svg height="1000" preserveaspectratio="xMidYMid meet" style="width: 100%; height: 100%; transform: translate3d(0px, 0px, 0px);" viewbox="0 0 1000 1000" width="1000"
    xmlns="http://www.w3.org/2000/svg">
    <defs>
        <clippath id="__lottie_element_2">
            <rect height="1000" width="1000" x="0" y="0"></rect>
        </clippath>
        <clippath id="__lottie_element_4">
            <path d="M0,0 L3048,0 L3048,2431 L0,2431z"></path>
        </clippath>
    </defs>
    <g clip-path="url(#__lottie_element_2)">
        <g clip-path="url(#__lottie_element_4)" opacity="1" style="display: block;" transform="matrix(0.5006899833679199,0,0,0.5006899833679199,-263.051513671875,-180.58868408203125)">
            <g class="H01 2k" opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.42333984375,488.25836181640625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAA...MC2S3oHLwAAAABJRU5ErkJggg=="></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9947565197944641,-0.10227109491825104,0.10227109491825104,0.9947565197944641,452.203369140625,619.6126708984375)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAA...BJRU5ErkJggg=="></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.40704345703125,490.92486572265625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAAAAWiCAYA...3+XcSAElFTkSuQmCC"></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.42333984375,488.25836181640625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAAAAWiCA...AAASUVORK5CYII="></image>
            </g>
        </g>
    </g>
</svg>

Here是原始文件。

但是每当我尝试通过浏览器显示它时,我都会收到此错误:
This page contains the following errors:
error on line 1 at column 982067: Namespace prefix xlink for href on image is not defined
Below is a rendering of the page up to the first error.

我不知道为什么。请问怎么了?

最佳答案

<svg>元素缺少 xlink 的声明命名空间,尽管它在 <image> 中使用元素。所以只需添加如下:

<svg height="1000" preserveaspectratio="xMidYMid meet" style="width: 100%; height: 100%; transform: translate3d(0px, 0px, 0px);" viewbox="0 0 1000 1000" width="1000"
    xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

SVG2 deprecated the xlink namespace for href attributes. .所以以后,改xlink:href="..."href="..."将是更好的解决方案。

关于未定义图像上 href 的 SVG 命名空间前缀 xlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59138117/

相关文章:

image - 使用SandcaSTLe将图像添加到Welcome.aml

javascript - 在 JavaScript 中动态创建 SVG 链接

validation - 如何声明 xlink 命名空间以验证 Docbook 5 链接?

html - 如何通过 xlink :href attribute with CSS? 选择 XML 元素

java - 贾克斯布 + Jersey 。如何解码多个命名空间

javascript - 在 Highcharts 中更改 SVG 描边选项

svg - 如何在D3轴刻度中获取数字值而不是对数值?

html - 在 mhtml5 svg 中绘制球体

javascript - d3 raise() 不适用于特定选择

javascript - 在 Chrome 中获取 getSVGDocument 的未定义结果,在 Firefox 中工作正常