引用与当前正在处理的文件位于同一文件夹中的文件的语法

Syntax to reference a file which is in the same folder as the file you are currently working on

问。使用相对引用,您将使用什么语法来引用名为 image.gif 的文件 哪个与您当前正在处理的文件位于同一文件夹(名为 pass2)?

一个。

<img src ="image.gif">

乙。

<img src="/image.gif">

摄氏度。

<img src="pass2/image.gif">

D.

<img src="/pass2/image.gif">

我会 select 选项 A,因为我正在处理同一个文件夹。因此,无需从根目录更改文件夹。但是没有答案,所以无法验证这一点。

如果图片在同一个文件夹中,那么您可以使用下面的

<img src="image.gif" alt="My test image">

From MDN :

To link to a target file in the same directory as the invoking HTML file, just use the filename, e.g. my-image.jpg.

To reference a file in a subdirectory, write the directory name in front of the path, plus a forward slash, e.g. subdirectory/my-image.jpg.

To link to a target file in the directory above the invoking HTML file, write two dots. So for example, if index.html was inside a subfolder of test-site and my-image.jpg was inside test-site, you could reference my-image.jpg from index.html using ../my-image.jpg.

You can combine these as much as you like, for example ../subdirectory/another-subdirectory/my-image.jpg.

For More