如何让 CSS URL 背景图像显示在 localhost 中?

发布于 2024-09-02 08:32:20 字数 661 浏览 4 评论 0原文

我刚刚安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落墨 2024-09-09 08:32:20

样式表中的图像路径应该位于图像相对于样式表的位置,例如,如果您的 .css 文件位于网站上的类似目录中:

/css/styles.css

您的路径应该看起来像这样(进入一个目录,然后进入images

background-image:url(../images/feather_email2.jpg);

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:

/css/styles.css

Your path should look like this (go up a directory, then into images)

background-image:url(../images/feather_email2.jpg);
倒数 2024-09-09 08:32:20

您可以尝试 base 标签 - 最流行的支持浏览器 - 然后提供相对于 base 标记的 href 属性的路径。或者确保提供相对于 CSS 样式表的正确路径

You can try the base tag - supported in most popular browsers - and then supply paths relative to the href attribute of the base tag. Or make sure you supply correct paths relative to the CSS stylesheet

凉墨 2024-09-09 08:32:20

尝试使用 ./ 而不是 / 并确保指定正确的路径。

Try using ./ instead of / and make sure that you are specifying the correct path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文