【问题标题】:SVG cannot set width and height in firefoxSVG 无法在 Firefox 中设置宽度和高度
【发布时间】:2013-02-09 06:40:46
【问题描述】:

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

一个简单的结构化html,带有一个宽度和高度为700px的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 svg


【解决方案1】:

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

为避免此问题,请放置一个与画布大小相同的不可见矩形,或其他形状以占据 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>

【讨论】:

    猜你喜欢
    • 2016-10-09
    • 1970-01-01
    • 2017-12-26
    • 2013-11-02
    • 2018-10-04
    • 2015-03-18
    • 2017-09-15
    • 2014-02-17
    相关资源
    最近更新 更多