Html 图像未显示在 Github Pages 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41468951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Images not displaying in Github Pages?
提问by Carlton
I added a project site to my Github project. But some photos are not displaying in the site.
我在我的 Github 项目中添加了一个项目站点。但是有些照片没有显示在网站上。
Img code:
图像代码:
<img src="img/screenshot2.PNG" class="img-responsive" alt=""> </div>
folder structure (img is a folder):
文件夹结构(img是文件夹):
img
Screenshot2.png
index.html
I tried with .png
and .PNG
(some earlier SO answers suggested it) and none of them work
我尝试过.png
和.PNG
(一些较早的 SO 答案建议它),但它们都不起作用
Any solutions?
任何解决方案?
回答by Carlton
Nevermind, I solved it.
没关系,我解决了。
If anyone has the same problem.
如果有人遇到同样的问题。
GitHub Pages are case sensitive. Not only for folders, but also for image names.
GitHub 页面区分大小写。不仅适用于文件夹,还适用于图像名称。
回答by Quentin
Write what you see.
写下你看到的。
It is Screenshot2.png
. With a lower-case png
and a capital S
at the start.
它是Screenshot2.png
。以小写png
和大写S
开头。
回答by martin-martin
As @dnivog mentioned, GitHub's servers take a little time to update files.
正如@dnivog 提到的,GitHub 的服务器需要一点时间来更新文件。
If nothing of the above addresses your situation, just check back in a little while. ?
如果以上都没有解决您的情况,请稍后再回来查看。?
回答by Saloni Sinha
While hosting a website on Github,I faced the same issue.The image file was saved as an .jpg extension on my local(in small letters) and It was working fine. I pushed the same to github. That did not work.
在 Github 上托管网站时,我遇到了同样的问题。图像文件在我的本地保存为 .jpg 扩展名(小写字母)并且工作正常。我把同样的东西推到了github。那没有用。
I had to change the extension to .JPG (in caps)since it was the original extension of the image.Github Pages are case sensitive to the name of the files being uploaded.
我不得不将扩展名更改为 .JPG(大写),因为它是图像的原始扩展名。Github 页面对上传文件的名称区分大小写。
回答by Timothy Ayegbede
I had a folder on my laptop named "assets", but when I pushed to Github it became "Assets". I had to change it in my HTML so I could view the images on the Github page
我的笔记本电脑上有一个名为“资产”的文件夹,但是当我推送到 Github 时,它变成了“资产”。我不得不在我的 HTML 中更改它,以便我可以在 Github 页面上查看图像
回答by deshraj singh
You can try by putting the "image link address" from the github repository, in the 'src' attribute of the 'img' tag of the HTML code of your file.
您可以尝试将 github 存储库中的“图像链接地址”放在文件 HTML 代码的“img”标签的“src”属性中。
回答by Elharony
I had this problem today. I solved it by:
我今天遇到了这个问题。我通过以下方式解决了它:
- Double-check the
Case Sensitive
of the images (i.e.Screenshot.png
isn't the same asScreenshot.PNG
or evenscreenshot.png
) - Double-check the
PATH
of the image. For me; It was../img/myImg.jpg
, and I changed it to./img/myImg.jpg
to point to the current directory of the project
- 仔细检查
Case Sensitive
图像的(即Screenshot.png
与Screenshot.PNG
或什至不相同screenshot.png
) - 仔细检查
PATH
图像。为了我; 是的../img/myImg.jpg
,我将其更改./img/myImg.jpg
为指向项目的当前目录
After fixing the 2 mentioned issue above, it worked fine... Hope it help you get unstuck!
解决上面提到的 2 个问题后,它工作正常......希望它可以帮助你摆脱困境!
回答by Seiont
I had this exact same problem, GitHub Pages appears to be case-sensitive for images, and I wrote .JPG instead of .jpg, once I changed my image extension to be lowercase it worked.
我遇到了完全相同的问题,GitHub Pages 似乎对图像区分大小写,我写了 .JPG 而不是 .jpg,一旦我将图像扩展名更改为小写,它就起作用了。
回答by bloudraak
I had a similar issue, except I used git-lfs to manage the images. GitHub Pages doesn't support LFS, which will prevent the image from being displayed.
我有一个类似的问题,除了我使用 git-lfs 来管理图像。GitHub Pages 不支持 LFS,这将阻止显示图像。
回答by Daniel
I struggled quite a while until I saw one post by Elharony: https://stackoverflow.com/users/5560399/elharonytalking about case sensitivity. It turned out Jupyter notebook is case insensitive for image files, but GitHub is. That solved my problem.
我挣扎了一段时间,直到我看到 Elharony 的一篇帖子:https://stackoverflow.com/users/5560399/elharony 谈论区分大小写。事实证明,Jupyter notebook 对图像文件不区分大小写,但 GitHub 是。那解决了我的问题。