我一直试图解决这个问题几天。我的背景图像没有显示,但图像大小(空白区域)显示。这是我的代码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表的开头,背景图像在“正文”中。在此先感谢您的所有帮助,非常详细的答案是首选。
你可以做两件事........第一件事改变图像位置并保存你保存html文件的地方......第二件事
#contact{
background-image: url("C:\Users\omar\Pictures\notaryweb\redphone.JPG");
width: 100%;
height: 105%;
background-repeat: no-repeat;
}
使用这个你的错误就是你使用正斜杠它会反向斜线..
你必须在你的道路上使用file:///
。如下
background-image: url("file:///C:/Users/omar/Pictures/notaryweb/redphone.JPG");
另外,确保文件确实存在。
你在制作斜线错误请放回斜线“\”
错误:url(“C:\ Users \ omar \ Pictures \ notaryweb / redphone.JPG”)
更正:网址(“C:\ Users \ omar \ Pictures \ notaryweb \ redphone.JPG”)
并确保您在此路径上有图片。
将图像保留在Web的上下文路径中始终是一种更好的做法。最好在您的网络中创建一个图像文件夹并使用它。这样做也不需要用反斜杠替换正斜杠。
您应该将C:\ Users \ omar \ Pictures \ notaryweb / redphone.JPG更改为C:\ Users \ omar \ Pictures \ notaryweb \ redphone.JPG。
你也应该将height: 105%
从百分比改为height: 105px
。