如何链接相同或不同文件夹中的html页面?
如果 html 页面位于相同或不同的文件夹中,而无需编写完整路径,如何链接到它们?
How can I link to html pages if they are in same or different folders without writing full path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
在同一文件夹中,只需使用文件名:
在父文件夹的目录中:
在子目录中:
Within the same folder, just use the file name:
Within the parent folder's directory:
Within a sub-directory:
此外,这将进入一个目录,然后返回到另一个子文件夹。
要进入多个目录,您可以这样做。
为了追根溯源,我用这个
Also, this will go up a directory and then back down to another subfolder.
To go up multiple directories you can do this.
To go the root, I use this
另外,如果要引用根目录,可以使用:
which willrefer to root。 因此,假设我们所在的文件嵌套在几层文件夹中,并且您想要返回主index.html:
Robert 提供了进一步的相对路径解释。
In addition, if you want to refer to the root directory, you can use:
Which will refer to the root. So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:
Robert is spot-on with further relative path explanations.
在层次结构中向上移动一个文件夹,您的链接将如下所示:
您可以使用So 从 /webroot/site/pages/folder1/myotherpage.htm 访问文件夹 /webroot/site/pages/folder2/mypage.htm ,
You can go up a folder in the hierarchy by using
So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:
使用相对路径
主页可能是:
/index.html
二级页面:
/otherFolder/otherpage.html
链接如下所示:
use the relative path
main page might be:
/index.html
secondary page:
/otherFolder/otherpage.html
link would be like so:
如果您想链接到根目录,可以使用
/
或/index.html
如果您想链接到同一目录中的文件,只需输入文件名
要移回文件夹,您可以使用
要从根目录链接到员工目录中的索引页面,您可以这样做
If you'd like to link to the root directory you can use
/
, or/index.html
If you'd like to link to a file in the same directory, simply put the file name
To move back a folder, you can use
To link to the index page in the employees directory from the root directory, you'd do this
我要提醒您:如果您使用绝对路径,那么您的应用程序不能安装在服务器的“子目录”中!
例如, http://yourserver.com/yourapp 可能有效,但 http://myserver.com/apps/yourapp 不会!
I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!
eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!
简短回答:
. 表示当前目录
.. 表示上层目录,如 shell 上的
cd ..
命令。简单但棘手,我写这个答案主要是为了自己下次不要忘记。
index.html
中 CSS 的链接:或
这种情况应该是:
或
在这种情况下,路径必须 是:
Short answer:
. is for current directory
.. is for upper directory as in
cd ..
command on shell.Simple yet tricky, I write this answer primarily for myself not to forget next time.
The link to CSS in
index.html
:<link rel="stylesheet" href="style.css">
or<link rel="stylesheet" href="./style.css">
This case it should be:
<link rel="stylesheet" href="stylefiles/style.css">
or<link rel="stylesheet" href="./stylefiles/style.css">
In this case path must be:
<link rel="stylesheet" href="../stylefiles/style.css">
例如
,如果您的文件位于
folder2
的folder1
中你这样找到它
Use
For example if your file, lets say image is in
folder1
infolder2
you locate it this way
href="./page.htm" 为同一目录
href="../page.htm" 父目录
href="~/page.htm" 根目录或最上层目录。
href="./page.htm" for the same directory
href="../page.htm" parent directory
href="~/page.htm" root directory or the upper most dir.
下面的答案是我创建的,用于将另一个共享驱动器中的 html 内容链接到我要发送给经理的 html 页面。 当然,路径与您的使用相关,但就我而言,我只会向他们发送 html,并且从加载运行程序动态更新的所有其他内容都会为我更新。
节省了大量的纸张,而且他们可以根据自己的需要使用这些数字,而不仅仅是用这种方式打印硬拷贝。
Answer below is what I created to link html contents from another shared drive to the html page I would send out to managers. Of course, the path is relative to your using, but in my case, I would just send them the html, and everything else that is updated from load runner dynamically would be updated for me.
Saves tons of paper, and they can play with the numbers as they see fit instead of just a hard copy this way.
对于 ASP.NET,这对我的开发和部署很有用:
使用
runat="server"
和href="~/"
是转到根目录的关键。For ASP.NET, this worked for me on development and deployment:
Using
runat="server"
and thehref="~/"
are the keys for going to the root.这对我来说
被点击
This worked for me
<a href="preferedfile name.html">to be clicked <a/>
当我创建网页时,我发现将 Html 文件移动到不同的文件夹时,它会更改图像、视频、音乐、PDF 文件等的路径。使用它们,您必须走出 HTML 所在的文件位于,与
<代码>../HTML。 然后,当您退出时,根据页面内容的位置,插入,
When I Was creating a webpage, I found out that With moving Html files to different Folders, It changes the paths of the images, videos, music, PDF files, etc. With them, you have to go out of the file the HTML is located in, with the
../HTML
. Then when your out, depending on where your page content is, insert,