【问题标题】:Background Image shows up on Live-server, does not show up on Github Pages背景图像显示在实时服务器上,不显示在 Github 页面上
【发布时间】:2020-06-14 05:16:49
【问题描述】:

我的背景图片在实时服务器上完美运行,但在 Github 页面上却不显示。我读到 Github 页面区分大小写,您需要将 .jpg 更改为 .JPG。这样做之后,它使我所有的其他图像都可以工作,除了这个背景图像。这是代码行

.main-image {
    display: flex;
    justify-content: center;
    background-image: linear-gradient( to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6) ), url("../images/st-george.JPG");
    height: 200px;
    background-size: cover;
    height: 97rem;
}

我也试过了:

 url("/images/st-george.JPG")//Without the two dots before images "../images"

这同样适用于实时服务器,但不适用于 Github 页面。

当我尝试时

 url("./images/st-george.JPG")//One dot instead of two

它不适用于实时服务器或 Github 页面。

编辑:链接到我的 gitgub 页面: https://calebm5577.github.io/Orthodox-Church-Website/index.html github代码链接: https://github.com/Calebm5577/Orthodox-Church-Website

【问题讨论】:

    标签: css github github-pages


    【解决方案1】:

    从您位于css/style.csscss stylesheet 读取:

    .main-image {
      display: flex;
      justify-content: center;
      background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("./images/st-george.JPG");
      height: 200px;
      background-size: cover;
      height: 97rem; }
    

    the code on your repository匹配

    所以它试图从不存在的css/images/st-george.JPG 获取图像

    如果您将其更改为以下内容,它将起作用:

    linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url(../images/st-george.jpg)
    

    你的文件名是st-george.jpg不是st-george.JPG

    【讨论】:

    • 我把它切换到那个,它仍然是一样的。在我的项目中,我将文件名切换为 .JPG,这就是为什么它以 .JPG 开头。我只是将文本切换为您的放置方式,而没有将文件切换回来,网站上仍然没有背景图片。不知道你能不能看到一个?
    • @JSheckle 你忘了这两个点:../images/st-george.jpg
    • 目前github上有两个点。写成../images/st-george.jpg
    • @JSheckle 对不起我的错误,但是当我查看时:calebm5577.github.io/Orthodox-Church-Website/css/style.css 它显示“../images/st-george.JPG”而不是“../images/st-george.jpg”
    • 我更新了我的github,所以它再次大写../images/st-george.JPGgithub.com/Calebm5577/Orthodox-Church-Website/blob/master/sass/…
    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多