HTML初学者会经常遇到这样一个问题,如何正确引用一个文件。比如,怎样在一个HTML网页中引用另外一个HTML网页作为超链接(hyperlink)?怎样在一个网页中插入一张图片?......
字串6
如果你在引用文件时(如加入超链接,或者插入图片等),使用了错误的文件路径,就会导致引用失效(无法浏览链接文件,或无法显示插入的图片等)。
yueluo.net
为了避免这些错误,正确地引用文件,我们需要学习一下HTML路径。
yueluo.net
HTML有2种路径的写法:相对路径和绝对路径。 字串7
HTML相对路径(Relative Path) yueluo.net
同一个目录的文件引用
字串7
如果源文件和引用文件在同一个目录里,直接写引用文件名即可。
字串8
我们现在建一个源文件info.html,在info.html里要引用index.html文件作为超链接。 字串6
html路径是:c:\Inetpub\wwwroot\sites\. www.yueluo.net
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html www.yueluo.net
假设index.html路径是:c:\Inetpub\wwwroot\sites\webjx\index.html 字串5
在info.html加入index.html超链接的代码应该这样写: 月落网
<a href = "index.html">index.html</a> 月落
如何表示上级目录 字串5
HTML初学者会经常遇到这样一个问题, yueluo.net
../表示源文件所在目录的上一级目录,../../表示源文件所在目录的上上级目录,以此类推。
月落
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html 字串8
假设index.html路径是:c:\Inetpub\wwwroot\sites\index.html yueluo.net
html路径是:c:\Inetpub\wwwroot. 字串6
在info.html加入index.html超链接的代码应该这样写:
字串7
<a href = "../index.html">index.html</a>
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html 月落网
假设index.html路径是:c:\Inetpub\wwwroot\index.html
在info.html加入index.html超链接的代码应该这样写:
<a href = "../../index.html">index.html</a>
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html yueluo.net
假设index.html路径是:c:\Inetpub\wwwroot\sites\wowstory\index.html
在info.html加入index.html超链接的代码应该这样写:
字串8
<a href = "../wowstory/index.html">index.html</a>
如何表示下级目录
//www.webjx.com/tutorials. 字串9
引用下级目录的文件,直接写下级目录文件的路径即可。
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html 字串9
假设index.html路径是:c:\Inetpub\wwwroot\sites\webjx\html\index.html www.yueluo.net
在info.html加入index.html超链接的代码应该这样写: 月落网
<a href = "html/index.html">index.html</a> 字串7
假设info.html路径是:c:\Inetpub\wwwroot\sites\webjx\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\webjx\html\tutorials\index.html www.yueluo.net
在info.html加入index.html超链接的代码应该这样写: 字串8
<a href = "html/tutorials/index.html">index.html</a>
字串5
HTML绝对路径(Absolute Path) yueluo.net
HTML绝对路径(absolute path)指带域名的文件的完整路径。
假设你注册了域名www.21825.com,并申请了虚拟主机,你的虚拟主机提供商会给你一个目录,比如www,这个www就是你网站的根目录。
字串5
假设你在www根目录下放了一个文件index.html,这个文件的绝对路径就是: http://www.21825.com/index.html。 yueluo.net
假设你在www根目录下建了一个目录叫tutorials,然后在该目录下放了一个文件index.html,这个文件的绝对路径就是http://www.21825.com/html/chuzu/index.html。 www.yueluo.net