从子文件夹中选取根文件夹的图像
假设以下是我网站的目录结构:
现在在 index.html
中,我可以简单地引用图像,例如:
<img src="./images/logo.png">
但我想引用来自 sub.html
的相同图像。 src
应该是什么?
Let's say following is the directory structure of my website :
Now in index.html
I can simply refer images like:
<img src="./images/logo.png">
But I want to refer the same image from sub.html
. What should be the src
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
../images/logo.png
会将您移回一个文件夹。../../images/logo.png
会将您移回两个文件夹。/images/logo.png
无论您在哪里,都会带您返回根文件夹。../images/logo.png
will move you back one folder.../../images/logo.png
will move you back two folders./images/logo.png
will take you back to the root folder no matter where you are/.您可以使用相对路径引用图像:
或者您可以使用绝对路径:
/
表示这是服务器上的绝对路径,因此如果您的服务器位于 https://example.org/,从任何页面引用/images/logo.png
都将指向 https://example.org/images/logo.pngYou can reference the image using relative path:
Or you can use absolute path:
/
means that this is an absolute path on the server, So if your server is at https://example.org/, referencing/images/logo.png
from any page would point to https://example.org/images/logo.png相对引用是
如果您知道相对于服务器根目录的位置,这对于具有复杂嵌套目录层次结构的应用程序来说可能是最简单的方法 - 所有文件夹都是相同的。
例如,如果问题中描述的目录树相对于服务器的根目录,则 index.html 和 sub_folder/sub.html 都将使用:
如果 images 文件夹位于
等应用程序的根目录中foo
在服务器根目录下(例如http://www.example.com/foo
),然后是 index.html (http://www.example.com/foo /index.html
) 例如和 sub_folder/sub.html (http://www.example.com/foo/sub_folder/sub.html
) 都使用:The relative reference would be
If you know the location relative to the root of the server, that may be simplest approach for an app with a complex nested directory hierarchy - it would be the same from all folders.
For example, if your directory tree depicted in your question is relative to the root of the server, then index.html and sub_folder/sub.html would both use:
If the images folder is instead in the root of an application like
foo
below the server root (e.g.http://www.example.com/foo
), then index.html (http://www.example.com/foo/index.html
) e.g and sub_folder/sub.html (http://www.example.com/foo/sub_folder/sub.html
) both use:您的index.html可以执行
src="images/logo.png"
,而从sub.html您可以执行src="../images/logo.png"
Your index.html can just do
src="images/logo.png"
and from sub.html you would dosrc="../images/logo.png"
../
将带您到目录树上一个文件夹。然后,选择适当的文件夹及其内容。../
takes you one folder up the directory tree. Then, select the appropriate folder and its contents.当您将文件上传到服务器时请小心,有些书籍您的图像不会出现在网页上,并且会出现崩溃的图标,这意味着您的文件路径未正确排列或编码,当您具有以下文件结构时,代码应该像这样
文件结构:
->web(主文件夹)
->images(子文件夹)->logo.png(子文件夹中的图像)上面的代码如下,
如果您通过忽略文件结构将文件上传到网络服务器, 请遵循此标准
如果不创建文件夹 web 如果直接上传文件那么你的图像将被破坏你看不到图像,然后更改代码如下
谢谢->vamshi krishnan
when you upload your files to the server be careful ,some tomes your images will not appear on the web page and a crashed icon will appear that means your file path is not properly arranged or coded when you have the the following file structure the code should be like this
File structure:
->web(main folder)
->images(subfolder)->logo.png(image in the sub folder)the code for the above is below follow this standard
if you uploaded your files to the web server by neglecting the file structure
with out creating the folder web if you directly upload the files then your images will be broken you can't see images,then change the code as following
thank you->vamshi krishnan
当您将文件上传到服务器时请小心,有些书籍您的图像不会出现在网页上,并且会出现崩溃的图标,这意味着您的文件路径未正确排列或编码,当您具有以下文件结构时,代码应该像这样的文件结构:->web(主文件夹)->images(子文件夹)->logo.png(子文件夹中的图像)上面的代码如下遵循此标准
<
img src="../images/logo.jpg" alt="image1" width="50px" height="50px">
如果您通过忽略文件结构而不创建文件将文件上传到 Web 服务器web文件夹如果你直接上传文件那么你的图像将被破坏你看不到图像,然后更改代码如下
谢谢->vamshi krishnan
when you upload your files to the server be careful ,some tomes your images will not appear on the web page and a crashed icon will appear that means your file path is not properly arranged or coded when you have the the following file structure the code should be like this File structure: ->web(main folder) ->images(subfolder)->logo.png(image in the sub folder)the code for the above is below follow this standard
<
img src="../images/logo.jpg" alt="image1" width="50px" height="50px">
if you uploaded your files to the web server by neglecting the file structure with out creating the folder web if you directly upload the files then your images will be broken you can't see images,then change the code as following
thank you->vamshi krishnan