Absolute HTML path and relative path-PHP source code

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.