HTML有2種路徑的寫法:絕對路徑和相對路徑


HTML有2種路徑的寫法:絕對路徑和相對路徑

版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/l18848956739/article/details/53411241

HTML相對路徑(Relative Path)
同一個目錄的文件引用
如果源文件和引用文件在同一個目錄里,直接寫引用文件名即可。

我們現在建一個源文件info.html,在info.html里要引用index.html文件作為超鏈接。

假設info.html路徑是:c:/Inetpub/wwwroot/sites/blabla/info.html
假設index.html路徑是:c:/Inetpub/wwwroot/sites/blabla/index.html
在info.html加入index.html超鏈接的代碼應該這樣寫:

<a href = "index.html">index.html</a>

如何表示上級目錄
../表示源文件所在目錄的上一級目錄,../../表示源文件所在目錄的上上級目錄,以此類推。

假設info.html路徑是:c:/Inetpub/wwwroot/sites/blabla/info.html
假設index.html路徑是:c:/Inetpub/wwwroot/sites/index.html
在info.html加入index.html超鏈接的代碼應該這樣寫:

<a href = "../index.html">index.html</a>

假設info.html路徑是:c:/Inetpub/wwwroot/sites/blabla/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/blabla/info.html
假設index.html路徑是:c:/Inetpub/wwwroot/sites/wowstory/index.html
在info.html加入index.html超鏈接的代碼應該這樣寫:

<a href = "../wowstory/index.html">index.html</a>

 
如何表示下級目錄
引用下級目錄的文件,直接寫下級目錄文件的路徑即可。

假設info.html路徑是:c:/Inetpub/wwwroot/sites/blabla/info.html
假設index.html路徑是:c:/Inetpub/wwwroot/sites/blabla/html/index.html
在info.html加入index.html超鏈接的代碼應該這樣寫:

<a href = "html/index.html">index.html</a>

假設info.html路徑是:c:/Inetpub/wwwroot/sites/blabla/info.html
假設index.html路徑是:c:/Inetpub/wwwroot/sites/blabla/html/tutorials/index.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM