我知道有几篇关于图像未显示在 GitHub Pages 中的帖子,但这些解决方案似乎并没有解决我的问题。在我的本地机器和 Netlify 上,页面工作正常,但在 GitHub Pages 上我丢失了所有图像。
所有图像都出现此错误:
<块引用>资源加载失败:服务器响应状态为 404()
这是 Github 页面的链接:https://mfagaikema.github.io/BarbershopWebsite/
这是我的存储库的链接:https://github.com/MFAGaikema/BarbershopWebsite/
我错过了什么?
答案 0 :(得分:0)
这是您的代码并进行适当的更改;
<link rel="stylesheet" href="src/css/style.css">
提供 https://mfagaikema.github.io**/BarbershopWebsite/**src/css/style.css
现在css代码如下;
线性梯度(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(/images/3day-shave-course.jpg)
给
https://mfagaikema.github.io/images/3day-shave-course.jpg
/BarbershopWebsite/ 缺失导致问题
现在在 css url 规则中添加站点文件夹名称
/BarbershopWebsite/images/3day-shave-course.jpg
控制台视图 - 我在我的本地控制台中进行了快速破折号以查看导致它的原因,并且按照上面的建议工作。
它会起作用。
更新 - 由于我无法在不创建不必要的 fork 的情况下访问 github,因此您需要在 src/css/style.css 文件中进行更改。只需复制粘贴下面的代码。
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-family: "Manrope", sans-serif;
}
html,
body {
overflow-x: hidden;
}
/*scrollbar*/
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #999;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/*Navigatiemenu top*/
header {
position: relative;
}
header nav {
width: 100vw;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
position: fixed;
z-index: 2;
background-color: rgba(38, 60, 73, 0.9);
}
header ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-left: 100px;
}
header ul li {
list-style-type: none;
padding: 0 50px;
-ms-flex-item-align: center;
-ms-grid-row-align: center;
align-self: center;
font-size: 16px;
}
header ul li a {
text-decoration: none;
color: white;
}
header ul li a:hover {
color: chocolate;
}
header ul li #appointment {
padding: 15px 30px;
background-color: saddlebrown;
-webkit-transition: all 0.2s;
transition: all 0.2s;
}
header ul li #appointment:hover {
background-color: chocolate;
color: black;
}
header #logo {
font-size: 50px;
text-decoration: none;
padding: 0px 20px;
margin: 5px;
border: 2px solid white;
color: white;
background-color: #263c49;
font-family: "Economica", sans-serif;
}
/*intro*/
.intro {
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.5)), to(rgba(0, 0, 0, 0.5))), url(../../images/3day-shave-course.jpg);
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(../../images/3day-shave-course.jpg);
background-size: cover;
height: 800px;
text-align: center;
color: white;
text-shadow: 2px 0 0 black, -2px 0 0 black, 0 2px 0 black, 0 -2px 0 black, 1px 1px black, -1px -1px 0 black,
1px -1px 0 black, -1px 1px 0 black;
letter-spacing: 4px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.intro .company-name {
padding: 0 20px;
margin: auto;
border: 5px solid #fff;
-webkit-animation: fade-names 1s linear forwards;
animation: fade-names 1s linear forwards;
-webkit-animation-delay: 0.5s;
animation-delay: 0.5s;
}
.intro h1 {
font-size: 150px;
}
.intro h2 {
margin-top: -20px;
padding-bottom: 20px;
font-size: 50px;
}
.intro h1,
.intro h2 {
font-family: "Economica", sans-serif;
font-weight: 100;
}
@-webkit-keyframes fade-names {
from {
opacity: 0;
-webkit-transform: scale(0.95);
transform: scale(0.95);
}
to {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
}
@keyframes fade-names {
from {
opacity: 0;
-webkit-transform: scale(0.95);
transform: scale(0.95);
}
to {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
}
/*markup content*/
.content {
margin: 0 300px;
}
.content > div {
padding: 80px 0 10px 0;
}
.content > div > p {
margin-bottom: 20px;
}
.content h2 {
color: #444;
position: relative;
margin-bottom: 20px;
}
.content h2::after {
content: "";
width: 70px;
position: absolute;
left: 0;
bottom: -2px;
border-bottom: #aaa8a8 solid 2px;
}
/*make appointment*/
.make-appointment .shops {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.make-appointment .shops .shop-text {
margin: 5px 0;
}
.make-appointment .shops .emmen-container,
.make-appointment .shops .zwolle-container {
width: 450px;
}
.make-appointment .shops .store-hours {
padding-top: 10px;
}
.make-appointment .shops .hours {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.make-appointment .shops .emmen-btn::after {
background-image: url(../../images/emmen-front.jpg);
}
.make-appointment .shops .zwolle-btn:after {
background-image: url(../../images/Stellar-Bakkes-13.jpg);
}
.make-appointment .shops .emmen-btn,
.make-appointment .shops .zwolle-btn {
height: 310px;
background: #000;
position: relative;
}
.make-appointment .shops .emmen-btn h3,
.make-appointment .shops .zwolle-btn h3 {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
z-index: 1;
color: #fff;
padding: 10px 20px;
background-color: chocolate;
font-weight: 200;
}
.make-appointment .shops .emmen-btn h3:hover,
.make-appointment .shops .zwolle-btn h3:hover {
text-decoration: underline;
}
.make-appointment .shops .emmen-btn::after,
.make-appointment .shops .zwolle-btn::after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
content: "";
background-size: cover;
background-repeat: no-repeat;
opacity: 0.9;
-webkit-transition: all 0.2s;
transition: all 0.2s;
}
.make-appointment .shops .emmen-btn:hover h3,
.make-appointment .shops .zwolle-btn:hover h3 {
color: #fff;
background-color: saddlebrown;
}
.make-appointment .shops .emmen-btn:hover::after,
.make-appointment .shops .zwolle-btn:hover::after {
opacity: 0.2;
}
/*about*/
.img-container {
display: -ms-grid;
display: grid;
width: 100%;
height: 450px;
gap: 40px;
-ms-grid-columns: 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr;
-ms-grid-rows: 1fr 1fr;
grid-template-rows: 1fr 1fr;
grid-template-areas: "salon salon materials"
"salon salon blowdry";
}
.img-container div {
background-size: cover;
}
#salon {
-ms-grid-row: 1;
-ms-grid-row-span: 2;
-ms-grid-column: 1;
-ms-grid-column-span: 2;
grid-area: salon;
background-image: url(../../images/emmen-salon.jpg);
}
#materials {
-ms-grid-row: 1;
-ms-grid-column: 3;
grid-area: materials;
background-image: url(../../images/materials-bakkes.jpg);
}
#blowdry {
-ms-grid-row: 2;
-ms-grid-column: 3;
grid-area: blowdry;
background-image: url(../../images/andre-emmen.jpg);
}
.text-container p:first-of-type {
margin-bottom: 10px;
}
/*# sourceMappingURL=style.css.map */
https://mfagaikema.github.io/BarbershopWebsite/src/css
解释 URL 时的 CSS 正在制作斜线以从域的根计算 IE。 /图像/无论.jpg 变成 https://mfagaikema.github.io/images/whatever.jpg
部分 URL 相对于样式表的来源进行解释,而不是相对于文档。
所以我从 css 文件所在的位置开始更改了 url 的相对路径 即https://mfagaikema.github.io/BarbershopWebsite/src/css
所以我们需要从 css 文件的位置向上两级,然后从那里转到图像文件夹 设置步骤说明
../images/3day-shave-course.jpg 使计算出的 url 为 https://mfagaikema.github.io/BarbershopWebsite/src/images/3day-shave-course.jpg
../../images/3day-shave-course.jpg 使计算出的 url 为 https://mfagaikema.github.io/BarbershopWebsite/images/3day-shave-course.jpg
我已经在 css 中进行了更改,只需将其替换到 src 文件夹中的 style.css 文件中即可。 背景图片:url(../../images/Stellar-Bakkes-13.jpg); 它会起作用。