Css 显示无后,Firefox中的内联SVG无法正确呈现,为什么?

Css 显示无后,Firefox中的内联SVG无法正确呈现,为什么?,css,firefox,rendering,display,inline-svg,Css,Firefox,Rendering,Display,Inline Svg,我们在应用程序中大量使用内嵌SVG。最近我发现了不必要的行为(特别是在Firefox中,但我在Chrome中也看到了类似的问题),不同svg的样式可能会相互干扰。我追踪了我当前的问题,直到使用了“display:none” 为了说明我的问题,请参阅下面附带的HTML。这包含两个圆形的德国国旗,第一个是隐藏的。在chrome中,您将看到一面圆形的德国国旗(这是正确的)。在Firefox中,你会看到一个方形的德国国旗(这是不正确的)。如果删除第一个div上的display:none,则两个标志都将正

我们在应用程序中大量使用内嵌SVG。最近我发现了不必要的行为(特别是在Firefox中,但我在Chrome中也看到了类似的问题),不同svg的样式可能会相互干扰。我追踪了我当前的问题,直到使用了“display:none”

为了说明我的问题,请参阅下面附带的HTML。这包含两个圆形的德国国旗,第一个是隐藏的。在chrome中,您将看到一面圆形的德国国旗(这是正确的)。在Firefox中,你会看到一个方形的德国国旗(这是不正确的)。如果删除第一个div上的display:none,则两个标志都将正确显示(圆形),或者如果删除整个第一个div,则第二个标志将正确显示(圆形)

为什么svg第一次出现时显示“无”,导致第二次出现时显示不正确

我想我可以通过在两个svg中使用不同的id来解决这个问题,但是因为我想在包含内联svg的公共html文件的多个页面上包含它们,所以目前这是非常不切实际的

<html>
<body>

<div style="display: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
    <defs>
        <circle id="bundesliga-a" cx="-52" cy="-52" r="32"/>
    </defs>
    <clipPath id="bundesliga-b">
        <use xlink:href="#bundesliga-a" overflow="visible"/>
    </clipPath>
    <g clip-path="url(#bundesliga-b)">
        <path fill="#FFF"
            d="M3.9 2.7S5.5.4 5-.5C4.5-1.6-8-14.2-8-14.2c.5-.9.7-1.8 1.1-2.7-1.4-1.6-1.6-3.6-.9-6.2.7-2.7 5.7-19.4-.7-31 .7-1.6 2.1-4.8 2.5-11.6 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d">
            <use xlink:href="#bundesliga-c" overflow="visible"/>
        </clipPath>
        <circle clip-path="url(#bundesliga-d)" fill="#D12028" cx="32" cy="32" r="32"/>
        <defs>
            <circle id="bundesliga-e" cx="32" cy="32" r="32"/>
        </defs>
        <clipPath id="bundesliga-f">
            <use xlink:href="#bundesliga-e" overflow="visible"/>
        </clipPath>
        <path clip-path="url(#bundesliga-f)" fill="#EEC258" d="M0 43.2h64V64H0z"/>
        <g>
            <defs>
                <circle id="bundesliga-g" cx="32" cy="32" r="32"/>
            </defs>
            <clipPath id="bundesliga-h">
                <use xlink:href="#bundesliga-g" overflow="visible"/>
            </clipPath>
            <path clip-path="url(#bundesliga-h)" fill="#292929" d="M0 0h64v20.8H0z"/>
        </g>
        <g>
            <defs>
                <circle id="bundesliga-i" cx="32" cy="32" r="32"/>
            </defs>
            <clipPath id="bundesliga-j">
                <use xlink:href="#bundesliga-i" overflow="visible"/>
            </clipPath>
            <path opacity=".07" clip-path="url(#bundesliga-j)" fill="#292929" d="M17.6 64H0V0h40"/>
        </g>
    </g>
</svg>
</div>

<div>
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
    <defs>
        <circle id="bundesliga-a" cx="-52" cy="-52" r="32"/>
    </defs>
    <clipPath id="bundesliga-b">
        <use xlink:href="#bundesliga-a" overflow="visible"/>
    </clipPath>
    <g clip-path="url(#bundesliga-b)">
        <path fill="#FFF"
            d="M3.9 2.7S5.5.4 5-.5C4.5-1.6-8-14.2-8-14.2c.5-.9.7-1.8 1.1-2.7-1.4-1.6-1.6-3.6-.9-6.2.7-2.7 5.7-19.4-.7-31 .7-1.6 2.1-4.8 2.5-11.6 1.1-12.8-6.6-21-17.1-21-6.6 0-16.2-.5-20.1-2.3-8.5-4-10.6-14.3-6.9-17.2l.2-.2c1.1-.7 3-.2 5 .5 1.6.5 3.2.9 5 .7h.7c10.3-1.4 9.6-10.3 9.6-10.3 0 1.6-2.3 1.8-2.7 2.1-3.2.5-7.5-.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 2.3 1.1 4.1.2 5.5-.5-.9-3-3.2-6.8-3.2-6.8s2.7 0 5 2.5c.7.9 2.7 7.5.5 15 0 0-.2-2.7-.5-3.9 0 0-3.2-1.8-8.4.7 0 .9 3.4 9.6 10 9.8.7 0 1.4 0 2.1-.2 5.9-1.1 9.8-10.7 11.8-19.1 1.7-.5 3.2-1 5-1.6 3.9-1.6 7.1-3.9 9.1-6.4-1.1 4.3-6.2 7.1-6.2 7.1.5.7.7 1.8.5 3-.2 1.4-1.8 3.6-2.7 4.8-.7.7-1.4 1.4-1.8 2.1-.7 1.1-.5 2.5.2 3 0 0-4.1 2.5-6.4 8.9 4.8.5 10.3-.2 11.8-1.4 0 0 .7-3-.5-5.5.9 0 1.4-.2 1.8-.5 1.8-1.4 1.1-3.9 1.1-3.9.9-1.6 3.6-7.3 5.2-8.2 1.6-.9 2.7-1.6 3.4-3.6.5-1.6-.2-3-1.1-3.9l-.2-.2c-2.5-2.7.9-5.9 1.4-9.3 1.1 1.6.2 3.6 0 5.2-.2 1.8-.5 4.1 1.6 5.2.7.5 1.8.7 3.2.5 3.2 0 3.9-2.1 3.9-2.1-5.7-5.9-6.4-10.6-5.5-13.2 1.5-4.5 5.1-9.3 5.1-9.3-1.1 3.6-3.7 7-2.8 11.8.9 5 4.3 9.3 7.7 13 2.5 2.5 6.4 4.6 7.7 6.6C-1.8-1.5-3.7-2.7-2.8.5c.5 1.8 1.1 2.1 3 2.3 1.1 0 .9.7 2.7-.2C4.3 1.9 5 .8 5 .8s3.1-1.3 2.2-2z"/>
    </g>
    <g>
        <defs>
            <circle id="bundesliga-c" cx="32" cy="32" r="32"/>
        </defs>
        <clipPath id="bundesliga-d">
            <use xlink:href="#bundesliga-c" overflow="visible"/>
        </clipPath>
        <circle clip-path="url(#bundesliga-d)" fill="#D12028" cx="32" cy="32" r="32"/>
        <defs>
            <circle id="bundesliga-e" cx="32" cy="32" r="32"/>
        </defs>
        <clipPath id="bundesliga-f">
            <use xlink:href="#bundesliga-e" overflow="visible"/>
        </clipPath>
        <path clip-path="url(#bundesliga-f)" fill="#EEC258" d="M0 43.2h64V64H0z"/>
        <g>
            <defs>
                <circle id="bundesliga-g" cx="32" cy="32" r="32"/>
            </defs>
            <clipPath id="bundesliga-h">
                <use xlink:href="#bundesliga-g" overflow="visible"/>
            </clipPath>
            <path clip-path="url(#bundesliga-h)" fill="#292929" d="M0 0h64v20.8H0z"/>
        </g>
        <g>
            <defs>
                <circle id="bundesliga-i" cx="32" cy="32" r="32"/>
            </defs>
            <clipPath id="bundesliga-j">
                <use xlink:href="#bundesliga-i" overflow="visible"/>
            </clipPath>
            <path opacity=".07" clip-path="url(#bundesliga-j)" fill="#292929" d="M17.6 64H0V0h40"/>
        </g>
    </g>
</svg>
</div>

</body>
</html>

好的,自从发布这个问题以来,我一直与公司的其他一些人联系,我们一起解决了这个问题

首先解决问题: 当您使用内联svg时,一个特定的svg包含两次,这个特定的svg使用id引用(例如定义的clipPath),并且第一个svg(至少在firefox上)位于一个html元素中,显示为:none。。然后,该svg第二次出现的id引用引用了第一个(隐藏)svg中的clipPath,这导致clipPath不显示,因此圆形图标变为方形

现在我的临时解决方案: 导致此问题的许多图标多次定义了完全相同的clipPath。我在页面正文的顶部包含了一个“虚拟”svg,定义了这个精确的clipPath:

<svg width="0" height="0" style="position: absolute;"><clipPath id="circle-32"><circle cx="32" cy="32" r="32"/></clipPath></svg>

然后,我从所有有问题的svg中删除了所有clipPath定义,并将它们替换为对#circle-32 clipPath的引用

这导致svg再次工作:)

长期解决方案: 我们决定,我们的设计师需要花费更多的时间来创建/导出适当的svg,这些svg不使用如此多的clipPath引用(或其他引用),将来我们将用重新绘制的图像替换整个svg集,这些图像正确导出以供web使用,并最小化这些构造

有人建议我将这篇博文转发给我们的设计师,其中包含如何创建合适的svg的技巧: