In actual Web development, paths are required for inserting images and including CSS files. If an incorrect file path is added, this will lead to invalid reference (unable to browse the linked file or display inserted images ). Many beginners are confused. next I will introduce the relative path and absolute path in detail.
HTML relative path
The path relationship between the file and other files (or folders) caused by the path of the file.
For example:
The absolute path of file 1.htm is: d:/www/html/1.htm
The absolute path of file 2.htm is: d:/www/html/2.htm
So the path of 1.htmrelative to 2.htm is: 1.htm
Usage of relative links:
If you want to link to the same directory, you only need to enter the name of the document to be linked, for example:
Webpage link
If you want to link to the next-level directory, you must first enter the directory name, then add "/", and then enter the file name, for example:
If you connect to the upper-level Directory, enter "../" first, and then enter the directory name and file name, for example:
Instance summary
Currently, 4 HTML files are classified as aaa.html bbb.html ccc.html index.html.
Aaa.html path: D:/www/adminwang/html/aaa.html
Bbb.html path: D:/www/adminwang/bbb.html
The ccc.html path is D:/www/ccc.html.
The index.html path is D:/www/index.html.
Link files in the same directory
For example, the code for connecting the ccc.html file chain to index.html is as follows:
1
Link to index webpage
Link the files in the previous Directory
For example, the code for connecting ccc.html to bbb.htmlis as follows:
1
Link ccc webpage
Link the files in the 2-layer Directory
For example, the code for connecting ccc.html to aaa.htmlis as follows:
1
Link ccc webpage
Link files in the lower-level Directory
For example, the code for connecting ccc.html to bbb.html is as follows:
1
Link bbb webpage
Link the files under the 2-layer Directory
For example, the code for ccc.htmllinking aaa.html is as follows:
1
Link aaa webpage
Absolute HTML path
The full path provided for the file, including the applicable protocol or drive letter. That is, the real complete path of files or directories on your home page on the hard disk. For example:
Http://www.adminwang.com/index.htm
D:/www/html/images/bg.jpg
There is nothing to say about the absolute path. if you have mastered the relative path, the absolute path is easy.