对于我自己的而非从其他网站借来的图像,正确的 img src 是什么?

cph*_*hil 4 html url image src

在我的计算机上,保存我的 .css 和 .html 文件的文件夹还包含一些我想插入到我的 html 中的图像。如果我从另一个网站借用图像,我了解如何获取图像的 url。如何获取位于我的文件夹中但尚未在 Internet 上的图像的 url?我是否必须将图片上传到其他网站才能获得链接?

我也明白我应该使用头部的基本标签来为我在 html 中的相对 url 提供链接,但在这个阶段,我没有包含图像的链接。

Ban*_*don 5

假设您的网页 ( .html) 位于C:\Project\index.html.

您可以将图像放在与网页相同的路径中,并与相对路径一起使用:

<img src="img.jpg"/>
Run Code Online (Sandbox Code Playgroud)

或者如果它在其他路径中,更像是您的网络根目录的某个子文件夹C:\Project\images::

<img src="/images/img.jpg"/>
Run Code Online (Sandbox Code Playgroud)

如果图像文件位于 的父文件夹中,请index.html使用:

<img src="../img.jpg"/>
Run Code Online (Sandbox Code Playgroud)

最后一种用法是使用绝对路径,不推荐使用:

<img src="C:/Project/images/img.jpg"/>
Run Code Online (Sandbox Code Playgroud)