【问题标题】:Background image not showing on firefox and chrome背景图像未在 Firefox 和 chrome 上显示
【发布时间】:2023-10-13 03:13:01
【问题描述】:

我遇到了一个问题,即背景图像没有显示在 chrome 和 firefox 上;它是全宽 div 的背景图像。任何帮助表示赞赏:) 请在下面查看我的代码:

#judges {
	width: 960px;
	margin: 0 auto;
	padding-top: 80px;
}

#judges .col1 p, #judges .col2 p {
	font-family: 'SohoGothicPro-regular', verdana, sans-serif;
	text-align: center;

}

#judges .col1 p, #judges .col2 p, #judges .col1 h3, #judges .col1 h3 {
	color: white;
} 

#judges_bg {
	clear: both;
	background-image: url('img/faces.png');
    position: absolute;
    width: 100vw;
    left: calc(-50vw + 50%);
    height: 380px;
    overflow: hidden;
}


#judges .readmore a {
	color: white;
}
    <div id="judges_bg" class="grey_overley">
    	<div id="judges"><!-- JUDGES START -->
			
			<div class="col1" style="color: white; text-shadow: 0 0 70px rgba(1,2,2,.99); font-family: 'SohoGothicPro-bold', verdana, sans-serif;">
				<div  class="wow slideInLeft" data-wow-duration="2s"  data-wow-offset="100"><p>The distinguished, international panel of judges is comprised of engineers and scientists representing the diversity of the profession. Lord Alec Broers is Chairman of the 2015 Judging Panel.</p></div>
			</div>
			
			<div class="col2">
			<div  class="wow slideInRight" data-wow-duration="2s" data-wow-offset="100">
    			<h3 style="color: white; text-shadow: 0 0 70px rgba(1,2,2,.99);">Who are the<br> <span>Judges?</span></h3></div>
    		</div>
			
			

			
    	</div><!-- JUDGES END -->
    	<div class="read_more"><a href="#" style="color: white;">Meet the Judges</a></div>
    </div>

【问题讨论】:

  • 你能看到是否设置了高度吗?如果不尝试明确设置高度。
  • 我签入萤火虫时没有设置高度

标签: css background-image


【解决方案1】:

大概是这条线不好:

background-image: url('img/faces.png');

改成:

background-image: url('../img/faces.png');

我知道问题所在。 img/faces.png 不存在!您正在使用 WordPress,您必须上传要使用的图像。转到图像并单击它,您将看到图像的完整路径名。复制它,并将其粘贴到 url 标签中,如下所示:url('COPY_LINK_HERE')。那必须解决它。

【讨论】:

  • 我同意@Dennis - 与其他任何事情相比,您的图像文件路径中的错误更可能是错误。我刚刚在 Firefox 35 中尝试了您的 HTML 和 CSS(使用我自己的一张全屏图像),您的标记完美运行。
  • 抱歉 dennis 刚刚尝试从 photoshop 重新导出图像并将其上传到小图片中,效果非常棒!奇怪的是,即使 safari 能够显示图像 chrome 也不是,因为它似乎是一个重命名为 .png 的 .psd。真对不起!现在感觉很愚蠢,但非常感谢
  • @Lukas_T,没问题,如果我的回答有帮助,您可以将其标记为正确答案:)
【解决方案2】:
width: 100vw;
left: calc(-50vw + 50%);

vw 单位不正确!

看到这个帖子:Is there any cross-browser javascript for making vh and vw units work

【讨论】:

  • 为什么要两个答案?
  • @Dennis 我标记为删除第二个(似乎问题不在于路径)