首页 > 解决方案 > 背景:返回 ERR_FILE_NOT_FOUND 的 url

问题描述

我正在为我的网站使用具有以下 CSS 代码的背景图片

body {
  line-height: 1.5em;
  letter-spacing: 1px;
  display: flex;
    flex-direction: column;
  min-height: 100vh;
  hyphens: auto;
    margin: auto; 
  background: url(/images/store_interior.jpg);
  background-attachment: fixed;
background-size: cover cover;
  height: 100vh; }

但是,当我查看站点时(本地视图,我还没有对整个站点进行 ftp),我的浏览器(Edge)告诉我以下内容:GET file:///C:/images/store_interior.jpg net ::ERR_FILE_NOT_FOUND style.css:1 图像文件位于图像中。我不确定为什么这根本不起作用,而且我从该文件中尝试过的任何其他图像也不能用作背景图像。

标签: htmlcss

解决方案


您提供的 CSS 指示以下文件结构:

Root Folder
├─ index.html
├─ style.css
└─ images
   └─ store_interior.jpg

但是,您的评论表明此文件结构:

Root Folder
├─ index.html
├─ css
│  └─ style.css
└─ images
   └─ store_interior.jpg

CSS 文件中的相对路径是相对于 CSS 文件本身的,而不是相对于根文件夹的。因此,您需要使用../向下一个文件夹。表示将 css 文件夹留回根文件夹。然后您可以使用images/实际进入图像文件夹。正确的路径应该是:../images/store_interior.jpg


推荐阅读