GitHub Pages 中的图片和相对链接

44

我创建了一个用户的GitHub页面。

现在,假设我有一个位于存储库根目录下的图像文件,位置为Images/Emoticons/Cool.png

我尝试将该图像插入到我的主要Index.html文件中。
我写入-
- <img src="\images\emoticons\cool.png"> 但是在线上和离线上都没有显示
- <img src="images\emoticons\cool.png"> 在线上没有显示但是我可以在离线时看到图片
- <img src="..\images\emoticons\cool.png"> 在线上和离线上都没有显示

应该怎么办?


2
如果您想从GitHub Pages链接到主存储库中的图像,则需要使用“原始”绝对链接。您可以通过转到主存储库中的图像,单击原始,然后复制该URL来获取它。 - Joshua Pinter
@JoshuaPinter,使用原始链接居然有效。但是你能解释一下为什么原始链接有效而普通链接无效吗?谢谢。 - Adarsh TS
1
@maddypie 使用普通路径时,index.html 会尝试在本地定位文件。也就是说,它会在当前目录中搜索名为 images 的文件夹,该文件夹包含一个名为 cool.png 的图像的文件夹 _emoticons_。 另一方面,如果您要访问的资源在此目录之外(即使它在同一个存储库中),需要提供原始链接来定位它。提供原始链接告诉 index.html 从网络检索资源,即不要尝试将其定位为本地资源。 - Omar Sharaki
这解释了我的疑问,@OmarSharaki。谢谢。 - Adarsh TS
2个回答

52

由于该网站由Linux服务器提供服务,路径区分大小写。

为了使其正常工作,请将提供的URL中的 emoticons 替换为 Emoticons

存储库的屏幕截图

此外,在 URL 中用正斜杠(/)替换反斜杠(\)。

下面的 HTML 代码应该正确显示图片。

<img src="images/Emoticons/cool.png" alt="hi" class="inline"/>

-7
try this

    <img src="images/emoticons/cool.png" alt="hi" class="inline"/>

Full Page 

<!DOCTYPE html>
<html>

  <head>
    <meta charset='utf-8' />
    <meta http-equiv="X-UA-Compatible" content="chrome=1" />
    <meta name="description" content="Home Page : My Github Web" />

    <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">

    <title>Home Page</title>
  </head>

  <body>

    <!-- HEADER -->
    <div id="header_wrap" class="outer">
        <header class="inner">
          <a id="forkme_banner" href="https://github.com/Avi-Aryan">View on GitHub</a>

          <h1 id="project_title">Home Page</h1>
          <h2 id="project_tagline">Avi Aryan</h2>

        </header>
    </div>

    <!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
    <section id="main_content" class="inner">
    <br />
    Hi ! <img src="images/emoticons/cool.png" alt="hi" class="inline"/><br /><br />
    I am a young coder currently having school time in India.<br />
    I love intelligent-coding, algorithms and logics and<br />
    enjoy playing Cricket and Badminton.<br />
    <br />
    My coding abilities are currently limited Autohotkey and only Autohotkey.<br />
    A listing of my Autohotkey works can be found <a href="Autohotkey.html">here</a>.<br />
    <br />
    You can always visit my <a href="http://www.avi-win-tips.blogspot.com">blog</a> if you are looking for cool tricks and cracks.<br />
    I write original , hard to find content.<br />
    <br />
    <hr><br />
    <h3>My Github Project List</h3>
    <ul>
    <li><a href="https://github.com/Avi-Aryan/Clipjump">Clipjump</a>
    <li><a href="https://github.com/Avi-Aryan/Sublime4Autohotkey">Sublime 4 Autohotkey</a>
    <li><a href="https://github.com/Avi-Aryan/AutoHotKey">Sublime Text Autohotkey Package</a>
    </ul><br />
    <h3>Other Links</h3>
    <ul>
    <li><a href="Autohotkey.html">Autohotkey Scripts Listing</a>
    <li><a href="http://avi-win-tips.blogspot.in/p/my-autohotkey.html">Blog Index</a>
    </ul>
    <br /><br />
    </section>
</div>

    <!-- FOOTER -->
    <div id="footer_wrap" class="outer">
    <footer class="inner">
        <h2><font color="#FFFFFF">Profiles</font></h2>
        <p>
            <a href="http://www.github.com/avi-aryan">Github</a><br />
            <a href="http://www.autohotkey.com/board/user/24563-a-v-i/">Autohotkey Forum</a><br />
            <a href=https://plus.google.com/110328513842183229282">Google +</a><br />
            <a href="http://www.avi-win-tips.blogspot.com">Blog</a>
        </p>
    </footer>



  </body>
</html>

据说在问题本身中不起作用,但我尝试了多次,它仍然不起作用。您可以查看存储库以确认。 - Avi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接