简体   繁体   English

Github 页面未加载 CSS 背景图像

[英]Github Pages Not Loading CSS Background Image

I am working on a project to copy a static website for practice.我正在做一个复制静态网站以进行练习的项目。 Here is the original .这是原文

My copy is hosted here on Github pages .我的副本托管在Github 页面上

As you can see, the original has an abstract background image.如您所见,原始图像具有抽象背景图像。 When running my site on live-server, the background shows up with no issue.在实时服务器上运行我的网站时,背景显示没有问题。 However, on Github the background does not show up, even though my directory structure did not change when I pushed it.然而,在 Github 上没有显示背景,即使我推送它时我的目录结构没有改变。

Here is the CSS that enables the background image, and works fine locally:这是启用背景图像的 CSS,并在本地正常工作:

background-image: url('/copy-site/assets/gradient-violet-bg.jpg');

Does Github not permit this sort of linking? Github 不允许这种链接吗? If so, what is the reason?如果是,原因是什么?

Just use the relative URL as background-image: url("./assets/gradient-violet-bg.jpg") and it will work.只需使用相对 URL 作为background-image: url("./assets/gradient-violet-bg.jpg")就可以了。

在此处输入图片说明

I can see that all the other images are correctly loaded in your site.我可以看到所有其他图像都已正确加载到您的站点中。 I sudjest you to move the background image in the folder with the other images ( becouse now is not present) and put that url in the background-image property.我建议您将文件夹中的背景图像与其他图像一起移动(因为现在不存在)并将该 url 放在background-image属性中。 So something like this所以像这样

background-image: url('assets/gradient-violet-bg.jpg');

and should work.并且应该工作。 Another way wold be to call directly url of the image from the source website另一种方法是从源网站直接调用图像的 url

background-image: url('https://www.kastapp.co/images/gradient-violet-bg.jpg');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM