What is the absolute path, what is the relative path, and what is the difference between the two?

Source: Internet
Author: User
Tags parent directory
Recently in the development of a project, want to reference the bootstrap file, has been wrong, so want to study the next relative path and absolute path relationship, to see how they are different.

What is an absolute path and a relative path?

DIVCSS5 for everyone to introduce the basic knowledge of relative path and absolute path, function, usage and other knowledge.

Relative path: The directory path that is established based on the location of the page where the file is referenced. Therefore, when a Web page that is saved in a different directory references the same file, the path used will not be the same, so it is referred to as relative.

Absolute path: The directory path that is based on the Web site's root directory. This is called absolute, meaning that when all Web pages reference the same file, the path used is the same.

In fact, the absolute path and the relative path are different, only in describing the directory path, the reference points used are different. Because the reference point of the root directory is the same for all files on the site, the path description using the root directory as the reference point is called an absolute path.

Second, the path special symbol

The following are some of the special symbols used to establish the path, and the meanings they represent.

"."--Represents the current directory, relative path. such as: <a href= "./abc" > Text </a> or
"..."--represents the previous level of the directory, relative to the path. such as: <a href= ". /abc "> Text </a> or
".. /.. /"-Represents the previous level of the previous level of the directory, relative to the path. such as:
"/"--Represents the root directory, the absolute path. such as: <a href= "/ABC" > Text </a> or
"D:/abc/"--Represents the root directory, the absolute path.

When using a relative path, we use the symbol "." To represent the current directory, with the symbol "..." To represent the parent directory of the current directory.

third, the popular way to explain

Absolute path as the name implies, fill in the absolute directory path address that is called absolute path, usually we directly use "/" to represent the directory path starting from the root directory, this is called the absolute path.
Relative path as the name implies, fill in the directory when the catalog file for reference, use ". /"or"./"refers to the upward level or use". /.. /"point to the higher level called the relative path.

Relative path absolute path of the referenced person by reference

Url1.htm Divcss5.gif. /subdir2/beref1.gif/dir1/subdir2/beref1.gif

Url2.htm Divcss5.gif. /.. /dir1/subdir2/beref1.gif/dir1/subdir2/beref1.gif

Url3.htm abc1.htm. /.. /dir2/abc1.htm/dir2/abc1.htm

Url4.htm abc2.htm. /abc2.htm/dir2/abc2.htm

Description
We use "/", ". /”、“.. /.. /"Separate styles and describes the path of the picture and the URL path relative to the absolute path relationship.

What is the role of absolute path and relative path?

Both the relative and absolute paths can be converted to each other, and the correct path can be paid attention to when the conversion takes effect in a valid link path.

Relative path vs. absolute path vs. css?
1, when we introduce the image address in the CSS, we may use the relative path and the absolute path
2, we in div+css HTML in HTML to introduce CSS files, the introduction of adding images will be used when the relative path and absolute path

Related Article

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.