为什么我的背景图片不起作用?

问题描述 投票:0回答:5

我一直试图解决这个问题几天。我的背景图像没有显示,但图像大小(空白区域)显示。这是我的代码HTML

<div id="contact">
<p>Let talk! contact us via e-mail, phone or text coming soon</p>
</div>

CSS

#contact{
 background-image: url("C:\Users\omar\Pictures\notaryweb/redphone.JPG");
width: 100%;
height: 105%;
background-repeat: no-repeat;
}

也不确定这是否重要,但我有

body{
background-color: #dddddd;
}

在我的css表的开头,背景图像在“正文”中。在此先感谢您的所有帮助,非常详细的答案是首选。

javascript html css web-deployment
5个回答
1
投票

你可以做两件事........第一件事改变图像位置并保存你保存html文件的地方......第二件事

#contact{
 background-image: url("C:\Users\omar\Pictures\notaryweb\redphone.JPG");
width: 100%;
height: 105%;
background-repeat: no-repeat;
} 

使用这个你的错误就是你使用正斜杠它会反向斜线..


0
投票

你必须在你的道路上使用file:///。如下

background-image: url("file:///C:/Users/omar/Pictures/notaryweb/redphone.JPG");

另外,确保文件确实存在。


0
投票

你在制作斜线错误请放回斜线“\”

错误:url(“C:\ Users \ omar \ Pictures \ notaryweb / redphone.JPG”)

更正:网址(“C:\ Users \ omar \ Pictures \ notaryweb \ redphone.JPG”)

并确保您在此路径上有图片。


0
投票

将图像保留在Web的上下文路径中始终是一种更好的做法。最好在您的网络中创建一个图像文件夹并使用它。这样做也不需要用反斜杠替换正斜杠。


0
投票

您应该将C:\ Users \ omar \ Pictures \ notaryweb / redphone.JPG更改为C:\ Users \ omar \ Pictures \ notaryweb \ redphone.JPG。

你也应该将height: 105%从百分比改为height: 105px

© www.soinside.com 2019 - 2024. All rights reserved.