HTML: Image won't display?

后端 未结 7 1836
遥遥无期
遥遥无期 2020-12-11 16:58

I\'m kind of new to HTML. I\'m trying to display an image on my website but for some reason, it just shows a blue box with a question mark in it. I\'ve looked everywhere on

7条回答
  •  没有蜡笔的小新
    2020-12-11 17:52

    Just to expand niko's answer:

    You can reference any image via its URL. No matter where it is, as long as it's accesible you can use it as the src. Example:

    Relative location:

    
    

    The image is sought relative to the document's location. If your document is at http://example.com/site/document.html, then your images folder should be on the same directory where your document.html file is.

    Absolute location:

    
    
    

    or

    
    

    In this case, your image will be sought from the document site's root, so, if your document.html is at http://example.com/site/document.html, the root would be at http://example.com/ (or it's respective directory on the server's filesystem, commonly www/). The first two examples are the same, since both point to the same host, Think of the first / as an alias for your server's root. In the second case, the image is located in another host, so you'd have to specify the complete URL of the image.

    Regarding /, . and ..:

    The / symbol will always return the root of a filesystem or site.

    The single point ./ points to the same directory where you are.

    And the double point ../ will point to the upper directory, or the one that contains the actual working directory.

    So you can build relative routes using them.

    Examples given the route http://example.com/dir/one/two/three/ and your calling document being inside three/:

    "./pictures/image.png"
    

    or just

    "pictures/image.png"
    

    Will try to find a directory named pictures inside http://example.com/dir/one/two/three/.

    "../pictures/image.png"
    

    Will try to find a directory named pictures inside http://example.com/dir/one/two/.

    "/pictures/image.png"
    

    Will try to find a directory named pictures directly at / or example.com (which are the same), on the same level as directory.

提交回复
热议问题