外部CSS图像将无法加载 [英] External CSS images won't load

查看:254
本文介绍了外部CSS图像将无法加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.

我的结构是这样的:

/
  index.html
  style/
    main.css
  images/
  test/
    test.html

/style/main.css 这样说:

body {
    background-image: url('/images/SomeImage.png');
    background-color: #000;
}

/index.html 拥有此CSS文件的链接,但正如标题所述,将不会加载任何图像.但这是相互连接的,因为背景实际上是黑色的,所以其余样式(但有图像)确实起作用.

/index.html has a link to this CSS file, but, as the title says, no image will load. But it's connected though, cause the background is actually black, so the rest of the style (but images) does work.

此外,如果我内部在/index.html 中编写相同的样式,则会加载背景.

Also, if I write the same style internally into /index.html the background will load.

此外,我创建了/test/test.html ,该内容只显示

Also, I created /test/test.html which says nothing but

<img src="/images/SomeImage.png" />

并且图像显示在该页面上.

and the image is displayed on that page.

因此,很明显,由于某种原因,我的/style/main.css 无法访问文件,而来自其他位置的任何其他文件也可以访问.为什么会这样?语法显然没有错.我迷路了.

So, obviously, for some reason my /style/main.css can't reach files, that any other file from any other location reaches. Why does this happen? There's clearly nothing wrong with the syntax. I'm lost.

推荐答案

将../添加到/images的开头,使其显示为../images/imagename.jpg

add ../ to the beginning of /images so it read ../images/imagename.jpg

以下是您的代码:

body {
background-image: url('../images/SomeImage.png');
background-color: #000;
}

这篇关于外部CSS图像将无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆