问题描述
出于某种原因,当我在 hostgator 索引文件(在 public_html 下)中引用 CSS 文件或图像文件时,它们不起作用,但是当我在本地测试时它起作用。这是我尝试使用通过 cPanel 上传到 public_html 文件夹的图像的示例:
<!DOCTYPE html>
<html>
<head>
<title>mydomain.com</title>
</head>
<h1>Here is an image</h1>
<img src="public_html/me.JPG" alt="pic of me">
<p style="background-color:#ECEBE9;">Here is more text
</p>
</body>
</html>
我试过了:
- 更改权限(public_html 中的所有内容均为 755 并且 public_html 是 750 as per hostgator's instructions)
- 使用完整路径:“/home/username/public_html/”(使用我的用户名并尝试使用“home3”而不是“home”)
- 将 JPG 放在名为 images 的子文件夹中并使用该路径名
我假设路径很明显,但我真的不明白为什么 index.html 文件无法从 hostgator 上的同一文件夹访问 CSS 或图像文件,所以请让我知道其他任何尝试.
解决方法
如果 me.JPG 与 html 文档位于同一文件夹中,请使用 src="me.JPG"
使用相对路径而不是绝对路径。
,<img src="public_html/me.JPG" alt="pic of me">
- 你能把public_html拿来用唯一的me.JPG吗?
- 请检查图片扩展名是 .JPG 还是 .jpg?