Basic HTML directory problem (difference between relative path and absolute path)

Basic HTML directory problem (difference between relative path and absolute path)
Relative path - a directory path established based on the location of the web page that references the file. Therefore, when web pages saved in different directories reference the same file, the paths used will be different, so it is called relative.
Absolute path - a directory path based on the root directory of the Web site. It is called absolute because when all web pages reference the same file, the path used is the same.
In fact, the difference between an absolute path and a relative path is only that different reference points are used when describing the directory path. Since the root directory is the same reference point for all files on the website, the path description method using the root directory as a reference point is called an absolute path.
The following are several special symbols used to establish paths and their meanings.
"."--represents the current directory.
".."--represents the upper directory.
"/"--represents the root directory.
Next, we assume that the website created by the reader has the directory path shown in the following figure.

If you want to reference the BeRef.gif file in the Ref.htm file, the relative path is as follows:

./SubDir2/BeRef.gif

In the reference path above, "." represents the current directory (Dir1), so "./SubDir2" represents SubDir2 in the current directory. In fact, you can also omit "./" and directly use this method to quote.

SubDir2/BeRef.gif

If you use an absolute path to reference the file with the root directory as the reference point, the reference path is as follows:

/Dir1/SubDir2/BeRef.gif

If the directory structure of the Web site is as shown below

What about the relative path of the BeRef.gif file?

If you want to reference the BeRef.gif file in the Ref.htm file, its relative path is as follows:

../SubDir2/BeRef.gif

In the reference path above, ".." represents the parent directory, so "/Dir2" represents the Dir2 subdirectory under the parent directory. If an absolute path is used for reference, the reference path is as follows:

/Dir2/BeRer.gif

Let's take a more complicated example to compare the use of relative paths and absolute paths. Assume that the website you created has the directory path as shown in the figure below.


We use a table to illustrate the relative path and absolute path that should be used when a file references another file in the above situation.

Cited by
Cited by
Relative Path
Absolute path
Ref1.htm BeRef1.gif ../SubDir2/BeRef1.gif /Dir1/SubDir2/BeRef1.gif
Ref2.htm BeRef1.gif ../../Dir1/SubDir2/ BeRef1.gif /Dir1/SubDir2/ BeRef1.gif
Ref1.htm BeRef2.htm ../../Dir2/ BeRef2.htm /Dir2/BeRef2.htm
Ref2.htm BeRef2.htm ../BeRef2.htm /Dir2/BeRef2.htm

What needs to be explained in the above table is the meaning of "../../".

".." represents the parent directory, and "../../" represents the parent directory of the parent directory. Therefore, as can be seen from the above table, if the referenced file exists in a subdirectory of the current directory, or in another subdirectory of the upper directory, it is more convenient to use a relative path. If not, just use the absolute path, which is more convenient. From the above table, we can also see that when the same file is referenced, the absolute path used to reference the file is the same.

<<:  Detailed use cases of vue3 teleport

>>:  How to connect Navicat to the docker database on the server

Recommend

Detailed explanation of Vue's props configuration

<template> <div class="demo"&g...

CSS3 implementation example of rotating only the background image 180 degrees

1. Mental Journey When I was writing the cockpit ...

How to forget the password of Jenkins in Linux

1.Jenkins installation steps: https://www.jb51.ne...

Use SQL statement to determine whether the record already exists before insert

Table of contents Determine whether a record alre...

Detailed explanation of LVM seamless disk horizontal expansion based on Linux

environment name property CPU x5650 Memory 4G dis...

How to use echarts to visualize components in Vue

echarts component official website address: https...

Mysql dynamically updates the database script example explanation

The specific upgrade script is as follows: Dynami...

mysql add, delete, modify and query basic statements

grammar Here is the generic SQL syntax for INSERT...

WeChat applet implements login interface

The login interface of WeChat applet is implement...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

Element sample code to implement dynamic table

Table of contents 【Code background】 【Code Impleme...

Recommend several MySQL related tools

Preface: With the continuous development of Inter...