Html 如何使用 a-href 标签链接回文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20599870/
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 link back out of a folder using the a-href tag?
提问by JakeGould
Alright so I have a page in a folder, the page is called jobs.html and the folder is simply called "jobs". Its a sub folder of my mine "website" folder. In the main directory of the "main" folder is my "home.html" file. When I try to do
好的,所以我在文件夹中有一个页面,该页面称为jobs.html,该文件夹简称为“jobs”。它是我的“网站”文件夹的子文件夹。在“main”文件夹的主目录中是我的“home.html”文件。当我尝试做
<a href="home.html">bla</a>
It malfunctions as it is looking for the home file in the jobs folder, which does not exist.
它在查找作业文件夹中不存在的主文件时出现故障。
So I ask, how can I reference out of a folder to call a file from the root folder?
所以我问,如何从文件夹中引用以从根文件夹中调用文件?
回答by JakeGould
Try setting your link to be your site root as so; note the /
in front of home.html
:
尝试将您的链接设置为您的站点根目录;注意/
前面的home.html
:
<a href="/home.html">bla</a>
Or if you know the path is definitely one directory down then just explicitly tell it to go down 1 directory; note the ../
in front of the home.html
.
或者,如果您知道路径肯定是向下一个目录,那么只需明确告诉它向下 1 个目录;注意../
前面的home.html
。
<a href="../home.html">bla</a>
回答by CDub
You can move up a directory by using ../
before your html document. So if home.html
is up one directory, you could do:
您可以通过../
在 html 文档之前使用来向上移动目录。所以如果home.html
是一个目录,你可以这样做:
<a href="../home.html">bla</a>