Javascript css在chrome中加载背景图像,但在firefox中不加载
我已经开发了一个网站,在chrome上运行顺利。但它在firefox中存在问题。它无法加载背景图像。我不明白为什么会发生这种情况。请在chrome和firefox中签出 CSSJavascript css在chrome中加载背景图像,但在firefox中不加载,javascript,html,css,Javascript,Html,Css,我已经开发了一个网站,在chrome上运行顺利。但它在firefox中存在问题。它无法加载背景图像。我不明白为什么会发生这种情况。请在chrome和firefox中签出 CSS #background { position: fixed; z-index: 1; background: url("../img/bg/photo_bg.jpg") 50% 50% no-repeat; background-size: cover; width: 100%; height:
#background {
position: fixed;
z-index: 1;
background: url("../img/bg/photo_bg.jpg") 50% 50% no-repeat;
background-size: cover;
width: 100%;
height: 100%;
display: inline-block;
}
您应该将显示器设置为“块”。
如果删除
display:inline block
属性,它似乎可以在Chrome和FF上工作
background {
position: fixed;
z-index: 1;
background: url("../img/bg/photo_bg.jpg") 50% 50% no-repeat;
background-size: cover;
width: 100%;
height: 100%;
/* display: inline-block; -- remove this */
}
如果您移除该属性,似乎没有其他区别,那么首先使用它的原因是什么
还有一点,我注意到有一个纯媒体屏幕和(-webkit-min-device-pixel ratio:1.5),不是所有的,也不是所有的规则只影响chrome/safari浏览器
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), not all, not all {
#background {
background: url(../img/bg/photo_bg_%402X.jpg) 50% 50% no-repeat;
background-size: cover;
}
}
你能把它做成一个,这样我们就可以从你的问题开始运行它了吗?另请参见主题。添加左侧:0,顶部:0,宽度:100vw,高度:100vh。应该可以。这在两种浏览器中都适用:与@StanGeorge相同,我也将top和left添加到0,然后出现背景。我猜可能是chrome的问题,因为有时候它足够聪明,可以自动默认一些属性,但firefox不会。top和left 0对我有效。我也在想这是怎么发生的。感谢@Anami的解释,也感谢stan georage在这里添加有意义的代码和解决方案描述。发布一个最小的、完整的、可验证的示例来演示您的解决方案。谢谢:-)!当然,我只是在inspector中将显示设置为阻塞,因为我在工作,所以没有时间做更多的工作,对不起。这是更好的解决方案,谢谢@Nikhil。请解释。现在我知道了问题的症结所在。没问题@Darshan,你可以标记答案,这样也可以帮助其他人。