相关疑难解决方法(0)

为什么样式不适用于 Firefox 中的 svg 元素?

我想将 CSS 样式应用于 SVG 元素内的 SVG<defs>元素。虽然在 Chrome 和 Internet Explorer(版本 11)中,以下代码可以正常工作,但在 Firefox 中却不能。如何将样式应用于defsFirefox 中的 SVG 元素?

#symbolcontainer.green #mysymbol { fill: green; }
Run Code Online (Sandbox Code Playgroud)
<svg>
    <g id="symbolcontainer" class="green">
        <defs>
            <g id='mysymbol'>
                <defs>
                    <circle id="myCircle" r="2" cx="2" cy="2"/>
                </defs>
                <use href="#myCircle"/>
            </g>
        </defs>
        <use href="#mysymbol" />
    </g>
</svg>
Run Code Online (Sandbox Code Playgroud)

在 chrome 和 Internet Explorer 中,圆圈为绿色(已应用样式),而在 Firefox 中为黑色(未应用样式)。

查看并使用此小提琴进行测试。

我在 stackoverflow 上搜索了“svg firefox style defs”,但没有找到我的问题的答案。

css firefox svg shadow-dom

5
推荐指数
1
解决办法
1723
查看次数

标签 统计

css ×1

firefox ×1

shadow-dom ×1

svg ×1