Home Web Front-end HTML Tutorial The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths

The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths

Jan 22, 2018 am 10:43 AM
href designation

This time I will bring you the href attribute of the HTMLa tagSpecify the relative path and absolute path usage, use the href attribute of the HTMLa tag to specify the relative path and absolute path usageNotesWhat are they? The following is a practical case. Let’s take a look.

In actual Web development, inserting

images, including CSS files, etc. all require paths. If the file path is added incorrectly, it will cause the reference to become invalid (unable to Browsing linked files, or inserted pictures cannot be displayed, etc.). Many beginners are confused. Below I will introduce relative paths and absolute paths in detail.

HTML relative path

refers to the path relationship with other files (or folders) caused by the path where this file is located.
For example:

文件1.htm的绝对路径是:d:/www/html/1.htm
文件2.htm的绝对路径是:d:/www/html/2.htm
那么:1.htm相对于2.htm的路径就是:1.htm
Copy after login

How to use relative links:

If you link to the same directory, you only need to enter the name of the document to be linked, for example:

<a href =”1 htm”>网页链接 </a>  
<img src=”bg.jpg” />
Copy after login

If you want to link to the next-level directory, you need to enter the directory name first, then add "/", and then enter the file name, for example:

<a href =”html/ next.htm”>  
<img src=”images/bg.jpg” />
Copy after login

If you want to connect to the upper-level directory, you need to enter ".. /", and then enter the directory name and file name, for example:

<a href = “../ www/index.htm”>
Copy after login

Example summary


现在有4个html文件分别是aaa.html bbb.html ccc.html index.html
aaa.html的路径为:D:/www/adminwang/html/aaa.html
bbb.html的路径为:D:/www/adminwang/ bbb.html
ccc.html的路径为:D:/www/ ccc.html
index.html的路径为D:/www/ index.html
Copy after login

1. Link files in the same directory

For example, ccc.html file link The code of index.html is as follows:

<a href="index.html">链接index网页</a>
Copy after login

2. Link to the file in the previous directory

For example, the code of bbb.
html link to ccc.html is as follows:

<a href="../ccc.html">链接ccc网页</a>
Copy after login

3. Link files in the upper 2-level directory

For example, the code for linking aaa.html to ccc.html is as follows:

<a href=”../../ccc.html”>链接ccc网页</a>
Copy after login

4. Linking files in lower-level directories

For example, ccc.html links to bbb.html The code is as follows:

<a href="adminwang/bbb.html">链接bbb网页</a>
Copy after login

5. Link files in the lower 2-level directory

For example, the code for ccc.html to link aaa.html is as follows:

<a href="adminwang/html/aaa.html">链接aaa网页</a>
Copy after login

HTML absolute path

Provide the file The full path to , including the applicable protocol or drive letter. That is, the real full path of the file or directory on your home page on the hard disk. For example:

http://www.adminwang.com/index.htm
d:/ www /html/images/bg.jpg
Copy after login

There is nothing to say about the absolute path. Once you master the relative path, the absolute path is very simple.


I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Detailed explanation of examples of HTML text formatting

Summary of frequently used tags in html

The basics of HTML editing (a must-read for beginners)

The above is the detailed content of The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What do src and href mean? What do src and href mean? Aug 16, 2023 pm 05:00 PM

src and href are respectively, 1. src is the abbreviation of source, which is used to specify the path of external resources. It is usually used to embed external files, such as pictures, audios, videos, etc. The src attribute is generally used on img, script, iframe and other tags. ; 2. href is the abbreviation of hypertext reference, which is used to specify the path of the target resource of the hyperlink. It is usually used to link to external documents or other pages. The href attribute is generally used on tags such as a and link.

How to fix missing MSVCP140D.dll issue on Windows How to fix missing MSVCP140D.dll issue on Windows Dec 22, 2023 am 10:51 AM

MSVCP140D.dll is a very important resource file. If an error occurs when running the program that MSVCP140D.dll is not specified to run on Windows, then you need to take it seriously, because if you do not handle it properly, the program will not be able to run. MSVCP140D.dll is not specified to run on Windows. Solution: Method 1: First download the msvcp140.dll file, decompress it and copy it to the corresponding system directory (the different directory addresses below correspond to different systems and cannot be mistaken) 1. For Windows95/98/Me system, copy it to the C:\Windows\System directory. 2.Window

What are the differences in functions and usage between the src attribute and the href attribute? What are the differences in functions and usage between the src attribute and the href attribute? Dec 28, 2023 am 08:20 AM

The src attribute and href attribute are commonly used attributes in HTML and are used to load external resources. Although they have similar purposes, there are some differences in usage and purpose. src attribute: The src attribute is used to specify external resources to be embedded in the document. It is mainly used to introduce external script files and media files into HTML documents. It can be used in the following situations: Introduce external JavaScript files: Link external JavaScript files to HTML pages through the src attribute.

What request is sent by href and src? What request is sent by href and src? Aug 17, 2023 pm 02:20 PM

Get requests sent by href and src. Detailed description: 1. The href attribute is used to specify the target resource of the link. When referencing an external style sheet, it will send a GET request to obtain the CSS file. When referencing the document, it will send a GET request to obtain the specified HTML file. When referencing an image, it will send a GET request. To obtain the specified image file; 2. The src attribute is used to specify the URL of the embedded resource. When referencing the image, it will send a GET request to obtain the specified image file. When referencing the audio, it will send a GET request to obtain the specified audio file, etc. .

Learn the important details about the difference between src and href! Learn the important details about the difference between src and href! Jan 06, 2024 am 09:11 AM

The difference between src and href, details you must know! When writing HTML pages, we often encounter the two attributes src and href. They are both used to reference external resources, such as script files, style files, or images. Although their purposes are similar, there are some differences in their specific usage and details. First of all, the src (source) attribute is mainly used to embed external resources, such as pictures or scripts. It is used to specify the address of a resource and embed its content into the current document. And href(

What is the difference between src and href? Find out quickly! What is the difference between src and href? Find out quickly! Jan 06, 2024 pm 09:09 PM

What is the difference between src and href? Find out quickly! In the process of web development, src and href are two commonly used attributes. Although they look similar, they actually have different uses and applicable scenarios. In this article, we’ll dive into the differences between src and href and explain them with concrete code examples. In HTML, src is an attribute used to specify an external resource to be embedded or referenced. It is usually used to reference image, audio, video or script files. Unlike this, href is a hyperlink

xlive.dll is not specified to run on Windows xlive.dll is not specified to run on Windows Jan 06, 2024 pm 07:29 PM

When many friends are playing games, the system suddenly prompts that the program cannot be started because xlive.dll is missing from the computer. Try reinstalling this program to solve this problem. What's going on? It's because the file is missing or not registered. Let's take a look at the specific solutions below. xlive.dll is not specified to run in Windows Solution 1. Start-Run Enter CMD, click OK or press the Enter key on the keyboard to open the administrator command prompt window. 2. Copy: for%1in(%windir%\system32\*.dll)doregsvr32.exe/s%1 command, open the administrator command prompt

What are src attributes and href attributes? What's the difference between them? What are src attributes and href attributes? What's the difference between them? Dec 28, 2023 pm 03:18 PM

What are src attributes and href attributes? What's the difference between them? In HTML, the src attribute and the href attribute are two commonly used attributes for referencing external resources. Although they are somewhat similar in functionality, there are some differences in usage and types of referenced resources. First, let's take a look at the src attribute. src is the abbreviation of source, which is mainly used to specify the address of embedding/referencing external resources. It can be applied to some tags such as <script>, <img>

See all articles