firefox - SVG 无法在 Firefox 中设置宽度和高度

标签 firefox svg

我正在努力解决这个非常烦人的问题....

一个简单的结构化 html,带有一个宽度和高度为 700 像素的 svg 元素:

<div id="wrapper">
    <div id="gameZone">
        <div id="background">
        <svg id="svgRoot" width="700px" height="700px">
            <circle cx="355" cy="600" r="10" id="ball" />
            <rect id="pad" height="15px" width="150px" x="280" y="670" rx="10" ry="20"/>
        </svg>
        </div>  
    </div>
</div>  

问题是为什么 svg 在 firefox 中显示时没有宽度和高度? 在 chrome 中,即它的工作 100%;

请帮我解决这个问题。

这是问题的屏幕截图:http://shaharmesh.hostingsiteforfree.com/differance.jpg

最佳答案

Firefox 调试器显示的大小与 svgRoot.getBBox() 的结果相同,即实际的 svg 内容边界大小。

为避免此问题,放置一个与 Canvas 大小相同的不可见矩形或其他形状以占据 svg 的左上角和右下角。

<div id="wrapper">
    <div id="gameZone">
        <div id="background">
        <svg id="svgRoot" width="700" height="700">
            <rect width="100%" height="100%" stroke="none" visibility="hidden" pointer-events="none" />
            <circle cx="355" cy="600" r="10" id="ball" />
            <rect id="pad" height="15" width="150" x="280" y="670" rx="10" ry="20"/>
        </svg>
        </div>
    </div>
</div>

关于firefox - SVG 无法在 Firefox 中设置宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15044635/

相关文章:

html - 为什么 SVG 元素内部会出现这个空白区域?

javascript - 使用 javascript 动态创建 SVG 路径,然后导出为 .pdf

css - 浏览器无法将相对单位(百分比)应用到由 fr 设置的空间

Firefox 插件 - 套接字

java - 在 FireFox 16、17、18 + 中使用 java

angular - 当我将 SVG 放入 ngFor 时 Angular 2 中的性能问题

html - 在 Firefox Addon 中显示摄像头

javascript - 有没有办法使用 javascript 检测 firefox 私有(private)模式

javascript - d3js 掩码在条形图上显示点

javascript - 如何在 d3 中向 svg 圆添加文本