twitter-bootstrap Bootstrap img src 不从本地硬盘加载图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28059385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:11:15  来源:igfitidea点击:

Bootstrap img src not loading images from local hard drive

htmltwitter-bootstrap

提问by Baber

I am facing an amazing problem that my html program loads images from web but not from local hard drive. I tried alot by changing path and folder but still the issue is same.

我面临一个惊人的问题,我的 html 程序从网络加载图像,而不是从本地硬盘驱动器。我通过更改路径和文件夹尝试了很多,但问题仍然相同。

<div class="row">
<div class="col-md-4">
    <div class="thumbnail">
        <figure>
            <img src="/images/img.jpg"
                 alt="Ghoomo Phiro Pakistan Adventure Club">
        </figure>
        <div class="caption">
            EveryThing goes there
        </div>
    </div>
</div>
<div class="col-md-4">
    <div class="thumbnail">
        <a href="#" class="thumbnail">
            <img src="https://www.google.com/images/srpr/logo3w.png"
                 alt="Ghoomo Phiro Pakistan Adventure Club">
        </a>
        <div class="caption">
            EveryThing goes there
        </div>
    </div>
</div>

Why does this work:

为什么这样做:

<img class="img-thumbnail img-responsive"
    src="http://upload.wikimedia.org/wikipedia/sr/0/0c/Firefox-logo.png"
    alt="" />

But not local images:

但不是本地图像:

<img class="img-thumbnail img-responsive"
     src="http://localhost/live/images/logo.png"
     alt="" />

回答by Avinash Kadimisetty

If you use src="/images/fileName" then the browser looks for images folder in the root directory. If images folder is in the same working directory then it won't work. You must have to replace it with either ./images/fileName or images/fileName

如果您使用 src="/images/fileName" 则浏览器会在根目录中查找图像文件夹。如果图像文件夹在同一个工作目录中,那么它将不起作用。您必须将其替换为 ./images/fileName 或 images/fileName

回答by Paulie

Check to see if your image is in one directory, and your css file in another. If this is the case, your css file will not be able to access the image without first going up the in the directory like so:

检查您的图像是否在一个目录中,而您的 css 文件是否在另一个目录中。如果是这种情况,您的 css 文件将无法访问图像,而无需先进入目录,如下所示:

<img src="../images/img.jpg"

回答by Alexander Shahbazov

I did it when my image moved from assets/images to views/* or public. Also you can use image_tag Rails helper.

当我的图像从资产/图像移动到视图/* 或公开时,我做到了。您也可以使用 image_tag Rails 助手。