图片在GitPages上无法显示,但在本地主机上正常工作。

huangapple go评论70阅读模式
英文:

Picture not showing up on GitPages, but works perfectly on local host

问题

在我的style.css中,我已经将背景图片设置为一张图片(Topbar1.png),并且在较小屏幕上设置了不同的图片(Topbar2.png)(位于style.css的83和89行)。

这两个在GitPages上都没有工作。我在Stack Overflow上寻找了不同的解决方案,但我没有能够解决它。

这是我的存储库链接:

以及我的GitPage链接:

  • 我相当确定我的相对路径是正确的 - 我在VS代码中编写代码,这是他们的自动完成功能在我选择图片时写的路径 - 但我确实尝试了不同的路径,以防万一。

  • 我尝试过重新命名文件(非常小心地使用确切的大小写),还尝试过使用完全不同的文件,看看是否会显示。我检查了GitHub上的存储库,以确保代码的编写和上传方式与我编写的方式完全相同。我还可以进入我的存储库并单击文件,图片确实显示出来。

  • 我已经清除了缓存,甚至尝试了用相同文件创建不同的存储库,以查看GitPage是否会以不同的方式工作。我还尝试在手机和不同的计算机上打开我的GitPage。它绝对不起作用,而且由于我在不同的几天内一直在解决这个问题,所以它绝对不仅仅是GitPages反映我的更改速度慢。

我的favicon(我命名为mIcon.jpg的文件)最初肯定是显示的,但我破坏了它,但通过查看我的历史记录,我无法确定是什么原因让它停止工作(位于index.html的第13行)。

我真的很感激帮助,我不明白为什么它可以在本地主机上工作,但在GitPages上不行,而且我没有认识的人可以帮助我解决这个问题。

英文:

I'm new to website design and I'm building a website for the company I work for. My site works perfectly on my local host, exactly how I wanted it to... but I am facing a problem with the top banner not showing up at all on my GitPage. (and also my favicon stopped working somewhere along the way and I didn't notice).

In my style.css, I've set the background image to a picture (Topbar1.png), and have it so that it is a different picture on smaller screens (Topbar2.png). [located in style.css lines 83 and 89].

Neither of these are working on Gitpages. I've looked for different solutions on Stack Overflow, but I haven't been able to figure it out.

This is a link to my repository:

And a link to my GitPage:

-I'm pretty sure my relative path is correct--I'm coding in VS code and this is how their autocomplete feature writes the path when I am selecting my pictures--but I did try different paths just in case.

-I have tried renaming the files (being very careful to use the exact case) and also tried using a different files altogether to see if that would show up. I checked the repository on GitHub to make sure the code is written and uploaded exactly how I had written it. I can also go into my repository and click on the files and the pictures do show up.

-I've cleared my cache and even tried making a different repository with the same files to see if the GitPage would work differently. I've also tried opening my GitPage on my phone and a different computer. It's definitely not working, and since I've been working on this problem over different a couple of days, it is definitely not just GitPages being slow to reflect my changes.

My favicon, (the file I've named mIcon.jpg) was definitely displaying in the beginning and I broke it, but going through my history hasn't been able to help me pinpoint exactly what I did to make it stop working. [located in index.html line 13].

I'd really appreciate the help, I don't understand how it can work on localhost, but not on GitPages and I don't know anybody IRL who can help me with this problem.

Edit: the css code

#topbar {
  height: 90px;
  font-size: 14px;
  transition: all 0.5s;
  color: #ffffff;
  padding: 0;
  background: linear-gradient( #000000, #8b0000);
  background-image: url("/assets/img/Topbar1.png");
  background-size: cover;
}

@media (max-width: 1100px)  {
  #topbar{
  background-image: url("/assets/img/Topbar2.png");
  background-size: cover;
  }
}

答案1

得分: -1

如果您打开“开发者工具”并转到“控制台”,您可以检查网站寻找丢失资源的位置。在您的情况下,它试图定位图片的位置在这里:https://dkirov1.github.io/assets/img/Topbar1.png

但正确的URL应该是:

https://dkirov1.github.io/MDTRedesign/assets/img/Topbar1.png

要修复这个问题,在您的CSS中,不要使用:

background-image: url("/assets/img/Topbar1.png");

改为:

background-image: url("../img/Topbar1.png");

对于Topbar2.png也是同样的方式。

关于网站图标,将:

更改为:

英文:

If you open Developer Tools and go to Console you can check where the website looks for the missing resources. In your case its trying to locate the image here: https://dkirov1.github.io/assets/img/Topbar1.png

But the correct url should be:

https://dkirov1.github.io/MDTRedesign/assets/img/Topbar1.png

To fix that, in your css, instead of using:

background-image: url("/assets/img/Topbar1.png");

Use:

background-image: url("../img/Topbar1.png");

Same goes for Topbar2.png.

Regarding the favicon, change:

<link href="/assets/img/mIcon.jpg" rel="icon">

To:

<link href="assets/img/mIcon.jpg" rel="icon">

huangapple
  • 本文由 发表于 2023年7月10日 16:26:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定