Use the current file location as the reference point to establish the path of the target file.
The concept of absolute pathThe full path of the entire file, such as X:/www/web/index.html, or http://waldo.com.cn/index.html. Both of these are absolute paths.
Detailed explanation of various ways to use relative pathsAssume that there is currently a page that wants to link to a page named test.html. The following shows the expressions of multiple relative paths.
Relative path example | The meaning of the path |
---|---|
href=test.html | Indicates that this page is in the directory where the current page is located |
href=./test.html | Indicates that this page is in the directory where the current page is located. A single dot has the same meaning as the direct file name above. |
href=/test.html | Indicates that this page is in the root directory of the website |
href=../test.html | Indicates that this page is in the directory above the current page |
href=../../test.html | Indicates that this page is under the directory one level above the current page (i.e., two directories above). Each time the parent directory increases, add a ../ |
href=../test.html | Indicates that this page is in the web subdirectory of the directory above the current page. |
The single slash / represents the root directory. You can use the / single slash to directly access the root directory at any level.
Assume that many places in the web page are linked to the about.html page in the web folder in the root directory of the website, then the html code should be written like this <a href='/about.html'>link to</a>.
Relative paths access files in the parent directory of the current page ../ represents the upper-level directory of the current file, assuming that the current page path is Waldo.com.cn/StaticPageFiles/SiteMapFiles/tag_11_1.htm. The page needs to link to the file X:www/web/StaticPageFiles/SiteMapFiles/Tag3/tag_3_1.htm. Then the link address in the current page should be <a href='../Tag3/tag_3_1.htm'>.NET标签</a>
.
PS: Since the current directory is Tag11, and the directory where the target file to be linked to the page is located is Tag3, which belongs to the same parent directory SiteMapFiles as the current directory, so you need to use ../ to link to the parent directory first, and then link to the parent directory. The target directory and files.
Relative paths access files in multi-level parent directories of the current pageSince ../ represents the upper-level directory of the current file, then ../../ represents the upper-level directory of the current file. Just superimpose ../ according to the number of parent levels to be obtained.
Relative paths access files in the subordinate directory to which the current page file belongs. Just use the current directory name/subordinate directory name/target file name. Assume that the directory where the current file is located is shiyousan.com/StaticPageFiles/SiteMapFiles/
. To link to the file under Tag3 in the current directory, the link address can be written like this: <a href='SiteMapFiles/Tag3/tag_3_1.htm'>链接</a>
, or you can also use ./, ./ is written like this: <a href='./SiteMapFiles/Tag3/tag_3_1.htm'>链接</a>。
.--------A single dot or direct directory name indicates the current directory.
.. --------Double dots represent the upper-level directory of the current file
/--------Single slash indicates the root directory of the current website
The above is a detailed explanation of how HTML uses relative paths to obtain files in directories at all levels introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for your support of the VeVb martial arts website!