如何让 CSS URL 背景图像显示在 localhost 中?
我刚刚安装了 xampp,并将我的实时站点之一带入其中,以便能够从本地主机开始工作。
因此,要查看我的网站,我导航到 localhost/example.com
我注意到 html 上的图像存在一些问题,例如:
<img src="/new_pictures/05.jpg" alt="Central Market"/>
图像不会显示,但后来我删除了 /
这有效:
<img src="new_pictures/05.jpg" alt="Central Market"/>
我似乎对 CSS 背景图像有类似的问题,但我无法让它工作 - 如果我删除那里的 / ,图像不会显示在实时站点上。如何使背景图像显示在本地主机上?
示例 CSS(适用于实时站点,但不适用于本地主机):
.outeremailcontainer {
height:60px;
width: 275px;
background-image:url(/images/feather_email2.jpg);
text-align:center;
float:right;
position:relative;
z-index:1;
}
谢谢!
I just installed xampp and I brought one of my live sites into it to be able to start working from localhost.
So to view my site, I navigate to localhost/example.com
I noticed some issues with images when on my html, I had for example:
<img src="/new_pictures/05.jpg" alt="Central Market"/>
Image wouldn't show up, but then I removed the /
and this works:
<img src="new_pictures/05.jpg" alt="Central Market"/>
I seem to have a similar problem with the CSS background image, but I can't get it to work-if I remove the / there, the image doesn't show up on the live site. How do I make the background image show up on localhost?
Example CSS (works in live site but not localhost):
.outeremailcontainer {
height:60px;
width: 275px;
background-image:url(/images/feather_email2.jpg);
text-align:center;
float:right;
position:relative;
z-index:1;
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
样式表中的图像路径应该位于图像相对于样式表的位置,例如,如果您的
.css
文件位于网站上的类似目录中:您的路径应该看起来像这样(进入一个目录,然后进入
images
)The image paths in your stylesheet should be where the image is relative to the stylesheet, for example if your
.css
file is in a directory like this on your site:Your path should look like this (go up a directory, then into
images
)您可以尝试
base
标签 - 最流行的支持浏览器 - 然后提供相对于base
标记的href
属性的路径。或者确保提供相对于 CSS 样式表的正确路径You can try the
base
tag - supported in most popular browsers - and then supply paths relative to thehref
attribute of thebase
tag. Or make sure you supply correct paths relative to the CSS stylesheet尝试使用
./
而不是/
并确保指定正确的路径。Try using
./
instead of/
and make sure that you are specifying the correct path.