[英]CSS “Background-image: url(…)” doesn't work on my website
I created my portfolio on Gitlab Pages. 我在Gitlab Pages上创建了我的投资组合。 My
style.CSS
work partially. 我的
style.CSS
可以部分工作。 background-image: url(..)
doesn't display in navigator. background-image: url(..)
未显示在导航器中。 However, everything else seems to be working. 但是,其他所有内容似乎都在起作用。 My content is in
public/img/.png
我的内容在
public/img/.png
I tried : 我试过了 :
url(/img/.png);
url(public/img/.png);
url(/public/img/.png);
You can check my code here : https://medjaherirany.gitlab.io/resume/ 您可以在这里检查我的代码: https : //medjaherirany.gitlab.io/resume/
Edit: I went into your code on the inspector, use background-image: url("../img/portrait0.png");
编辑:我进入了检查器上的代码,使用
background-image: url("../img/portrait0.png");
and it works. 而且有效。 I will include a screenshot.
我将包括一个屏幕截图。 This is used to go backwards in the directory.
这用于在目录中向后移动。
I hope this helps. 我希望这有帮助。
As I can see in your CSS file you have used 正如我在您的CSS文件中看到的那样,
figure {
background: url(/img/portrait0.png);
background-repeat: no-repeat;
background-position: 80% 111px;
height: 727px;
background-size: 690px;
background-color: #f2f2f2;
}
Change it to 更改为
figure {
background: url("img/portrait0.png");
background-repeat: no-repeat;
background-position: 80% 111px;
height: 727px;
background-size: 690px;
background-color: #f2f2f2;
}
Here actually your CSS says to look for img directory in the parent directory of "https://medjaherirany.gitlab.io/"
实际上,您的CSS在这里说要在
of "https://medjaherirany.gitlab.io/"
的父目录of "https://medjaherirany.gitlab.io/"
查找img目录。
But your code is in https://medjaherirany.gitlab.io/resume
That's why the browser was searching for "https://medjaherirany.gitlab.io/img/portrait0.png"
But actually it is in "https://medjaherirany.gitlab.io/resume/img/portrait0.png"
但是您的代码在
https://medjaherirany.gitlab.io/resume
这就是为什么浏览器在搜索"https://medjaherirany.gitlab.io/img/portrait0.png"
的原因,而实际上是在"https://medjaherirany.gitlab.io/resume/img/portrait0.png"
Here I changed the URL of background image and I got the image working. 在这里,我更改了背景图片的网址,并使图片正常工作。
Hope this helped you. 希望这对您有所帮助。 Feel free to ask any further doubts.
随时提出任何疑问。 Happy Coding
快乐编码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.