html - 背景:返回 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 图像文件位于图像中。我不确定为什么这根本不起作用,而且我从该文件中尝试过的任何其他图像也不能用作背景图像。
解决方案
您提供的 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
推荐阅读
- google-bigquery - 我可以从 bigquery 导出到使用不同凭据访问的存储桶吗?
- java - BeanUtils:将字符串日期格式的地图字段填充到日期属性
- java - Android grpc 执行失败
- django - 禁止更新 django 模型字段
- python - 在 for 循环中写入文本文件
- sql - 我们可以在 ColdFusion Query-of-Query 中使用“案例”吗
- c++ - c++中this指针的使用
- html - 如何在某人管理面板中添加二级菜单?
- android - 使用我的导航抽屉,某些活动的加载比其他活动更难
- android - android动态创建的微调器不滚动