Detailed explanation of how to use relative paths in HTML to obtain files at all levels of directories

Detailed explanation of how to use relative paths in HTML to obtain files at all levels of directories

The concept of relative path

Use the current file location as a reference point to establish the path to the target file.

The concept of absolute path

The 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 paths

Assume that there is a page that you want to link to a page named test.html. The following shows various ways to express relative paths:

Relative path example What the path means
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 parent directory of the current page
href="../../test.html" Indicates that this page is in the directory one level above the current page (that is, two levels above the current page). For each level of the previous directory, add a ../
href="../test.html" Indicates that this page is in the web subdirectory of the first-level directory on the current page

Relative path access to files in the root directory of the website

A single slash / represents the root directory. You can use the / single slash to directly access the root directory at any level.

Assuming that many places on the web page need to link to the about.html page in the web folder under the root directory of the website, the html code should be written like this: <a href='/about.html'>link to</a>.

Relative path access to files in the parent directory of the current page

../ indicates the parent directory of the current file. Assume 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 that the page needs to link is located is Tag3, which belongs to the same parent directory SiteMapFiles as the current directory, you need to use ../ to link to the parent directory first, and then link to the target directory and files under the parent directory.

Relative path access to files in multiple parent directories of the current page

Since ../ represents the parent directory of the current file, ../../ represents the parent directory of the current file. Just add ../ according to the number of parent levels to be obtained.

Relative path access to files in the subdirectory of the current page file

Just use the current directory name/subdirectory name/target file name. Assuming that the current file is located in the directory 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 use ./,./ like this: <a href='./SiteMapFiles/Tag3/tag_3_1.htm'>鏈接</a>。

Summarize

. --------A single dot or a direct directory name indicates the current directory

.. --------Double dots indicate the parent directory of the current file

/ --------A single slash indicates the root directory of the current website

The above is a detailed explanation of how to use relative paths in HTML to obtain files at all levels of directories. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Call and execute host docker operations in docker container

>>:  Detailed explanation of DBeaver connecting to MySQL version 8 and above and solving possible problems

Recommend

Detailed steps to start the Django project with nginx+uwsgi

When we develop a web project with Django, the te...

js uses FileReader to read local files or blobs

Table of contents FileReader reads local files or...

A Deeper Look at the Differences Between Link and @import

There are three main ways to use CSS in a page: ad...

Steps to install RocketMQ instance on Linux

1. Install JDK 1.1 Check whether the current virt...

SSH port forwarding to achieve intranet penetration

The machines in our LAN can access the external n...

js to implement file upload style details

Table of contents 1. Overview 2. Parameters for c...

Introduction to the use of alt and title attributes of HTML img tags

When browser vendors bend the standards and take i...

Tutorial on deploying springboot package in linux environment using docker

Because springboot has a built-in tomcat server, ...

Hello dialog box design experience sharing

"What's wrong?" Unless you are accus...

How to implement import and export mysql database commands under linux

1. Export the database using the mysqldump comman...

Use of Linux sed command

1. Function Introduction sed (Stream EDitor) is a...

Detailed explanation of TIMESTAMPDIFF case in MySQL

1. Syntax TIMESTAMPDIFF(unit,begin,end); Returns ...

How to set process.env.NODE_ENV production environment mode

Before I start, let me emphasize that process.env...

How to use indexes to optimize MySQL ORDER BY statements

Create table & create index create table tbl1...

CSS web page responsive layout to automatically adapt to PC/Pad/Phone devices

Preface There are many devices nowadays, includin...