Html 如何将超链接放置到“目录树中的上两层”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7051735/
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
How do I put a hyperlink to "two levels above in the directory tree"?
提问by user770022
I am trying to code my Home button. Is there a way to just climb back up the file structure, instead of using the absolute path like I have below.
我正在尝试编码我的主页按钮。有没有办法只爬回文件结构,而不是像我下面那样使用绝对路径。
I have a file index.html that I have at C:\Users\Randy\Documents\XML\
我有一个文件 index.html C:\Users\Randy\Documents\XML\
Heres my code:
这是我的代码:
<a id="my-family" href="C:\Users\Randy\Documents\XML\index.html">Home</a>
Heres where I am trying to come from: C:\Users\Randy\Documents\XML\project\xml
这是我试图来自的地方: C:\Users\Randy\Documents\XML\project\xml
回答by Tudor
to go two level up use "../../" and your normal url from two level up folder.
要上两级,请使用“../../”和上两级文件夹中的普通 url。
"../" in the path is used to go one level up. But, it can be used for more times, to go more levels up.
路径中的“../”用于上一级。但是,它可以使用更多次,以提升更多级别。
an example:
一个例子:
| HOME <br>
+- image.jpg<br>
|_
|
+- CONFIG<br>
|
+ PICTURE_CONFIG
|
+- myfile.html
myfile.html contains:
myfile.html 包含:
<img src="../../image.jpg" />
the second"../" goes from PICTURE_CONFIG to CONFIG folder
the first "../"goes from CONFIG to HOME folder
"image.jpg" searches in HOME folder for the file "image.jpg"
第二个“../”从PICTURE_CONFIG到CONFIG文件夹
第一个“../”从CONFIG到HOME文件夹
“image.jpg”在HOME文件夹中搜索文件“image.jpg”
回答by Shi
You can use ../index.html
to refer to index.html
in the parent directory.
您可以在父目录中使用../index.html
来引用index.html
。
回答by Dennis
I'm not sure exactly what you're asking, but in relative paths, ../
is 'up one level'.
我不确定你在问什么,但在相对路径中,../
是“上升一级”。
So, ../index.html
would take you to the index of the next directory up. Hope that helps.
所以,../index.html
会带你到下一个目录的索引上去。希望有帮助。
回答by Edd C.
<img src="picture.jpg">
WHEN picture.jpg is located in the same folder as the current page<img src="images/picture.jpg">
WHEN picture.jpg is located in the images folder located in the current folder<img src="/images/picture.jpg">
WHEN picture.jpg is located in the images folder located at the root of the current web<img src="../picture.jpg">
WHEN picture.jpg is located in the folder one level up from the current folder<img src="../../picture.jpg">
WHEN picture.jpg is located in the folder two levels up from the current folder
<img src="picture.jpg">
当 picture.jpg 与当前页面位于同一文件夹中时<img src="images/picture.jpg">
WHEN picture.jpg 位于当前文件夹下的图像文件夹中<img src="/images/picture.jpg">
WHEN picture.jpg 位于当前网站根目录下的图像文件夹中<img src="../picture.jpg">
WHEN picture.jpg 位于当前文件夹的上一级文件夹中<img src="../../picture.jpg">
WHEN picture.jpg 位于当前文件夹上两级的文件夹中
Hope this example help :)
希望这个例子有帮助:)
回答by Leland Hepworth
On Windows OS, the forward-slash (/) wasn't working, so I switched to back-slash (\) and that fixed it. For example, try using the following:
在 Windows 操作系统上,正斜杠 (/) 不起作用,所以我切换到反斜杠 (\) 并修复了它。例如,尝试使用以下内容:
"..\..\index.html"
回答by Kaushal Shah
It is working for me to go back to two level (parent folder) through hyper link reference.
通过超链接引用返回到两个级别(父文件夹)对我来说是有效的。