【问题标题】:Images in github pages and relative linksgithub页面和相关链接中的图像
【发布时间】:2013-06-13 01:23:49
【问题描述】:

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

现在,假设我在 repo 的根目录中有一个 Image 文件,位于 Images/Emoticons/Cool.png

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

应该怎么做?

【问题讨论】:

  • 如果您尝试从 GitHub 页面链接到主仓库中的图像,则需要使用“原始”绝对链接。您可以通过转到主存储库中的图像,单击 raw 然后复制该 URL 来获得它。
  • @JoshuaPinter,使用 原始链接 非常有效。但是你能解释为什么原始链接有效而普通链接无效吗?谢谢。
  • @maddypie 使用普通路径,index.html 尝试在本地定位文件。也就是说,它在当前目录中搜索名为 images 的文件夹,其中包含一个文件夹 emoticons,其中包含一个图像 cool.png。另一方面,如果您尝试访问此目录之外的资源(即使它在同一个 repo 中),则需要一个原始链接来定位它。提供原始链接告诉 index.html 从 Web 检索资源,即不要尝试将其视为本地资源。
  • 这解释了我的查询,@OmarSharaki。谢谢。

标签: html github


【解决方案1】:

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

为了完成这项工作,请将提供的网址中的emoticons 替换为Emoticons

另外,在 URL 中,将反斜杠 (\) 替换为正斜杠 (/)。

以下 HTML 代码应正确显示图像

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

【讨论】:

    【解决方案2】:
    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>
    

    【讨论】:

    • 据说这在问题本身中不起作用,但是我一次又一次地尝试它不起作用。您可以查看 repo 进行确认。
    猜你喜欢
    • 2019-09-22
    • 2016-07-03
    • 2013-04-04
    • 2018-02-09
    • 2022-07-19
    • 2013-05-05
    • 1970-01-01
    • 2017-10-27
    • 2021-12-21
    相关资源
    最近更新 更多