HTML beginners often encounter the problem of how to correctly reference a file. For example, how do you reference another HTML page as a hyperlink in an HTML page? How to insert a picture into a web page If you use the wrong file path when referencing a file (such as adding a hyperlink or inserting a picture, etc.), the reference will become invalid (the linked file cannot be browsed, or the inserted picture cannot be displayed, etc.). In order to avoid these errors and reference files correctly, we need to learn about HTML paths. There are two ways to write paths in HTML: relative paths and absolute paths. HTML Relative Path File references in the same directory If the source file and the referenced file are in the same directory, just write the referenced file name. We now create a source file info.html, and reference the index.html file as a hyperlink in info.html. Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path to index.html is: c:\Inetpub\wwwroot\sites\blabla\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "index.html">index.html</a> How to indicate the parent directory ../ represents the parent directory of the source file, ../../ represents the parent directory of the source file, and so on. Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path to index.html is: c:\Inetpub\wwwroot\sites\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "../index.html">index.html</a> Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path of index.html is: c:\Inetpub\wwwroot\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "../../index.html">index.html</a> Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path to index.html is: c:\Inetpub\wwwroot\sites\wowstory\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "../wowstory/index.html">index.html</a> How to indicate that a sub-directory references a file in a sub-directory? Simply write the path of the sub-directory file. Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path to index.html is: c:\Inetpub\wwwroot\sites\blabla\html\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "html/index.html">index.html</a> Assume that the path to info.html is: c:\Inetpub\wwwroot\sites\blabla\info.html Assume that the path to index.html is: c:\Inetpub\wwwroot\sites\blabla\html\tutorials\index.html The code to add a hyperlink to index.html in info.html should be written like this: <a href = "html/tutorials/index.html">index.html</a> HTML Absolute Path HTML absolute path refers to the complete path of the file with the domain name. Suppose you register the domain name www.jb51.net and apply for a virtual host. Your virtual host provider will give you a directory, such as www. This www is the root directory of your website. Suppose you put a file index.html in the www root directory, the absolute path of this file is: https://www.jb51.net/index.html. Suppose you created a directory called html_tutorials in the www root directory, and then placed a file index.html in the directory. The absolute path of this file is https://www.jb51.net/html_tutorials/index.html. |
<<: Implementation example of JS native double-column shuttle selection box
>>: Four ways to combine CSS and HTML
Preface When writing front-end pages, we often us...
Table of contents 1 What is function currying? 2 ...
Mind Map He probably looks like this: Most of the...
Preface I believe everyone has used the top comma...
Whether it is Samba service or NFS service, the m...
This article shares the specific code of canvas t...
Detailed explanation of Linux vi command The vi e...
I haven't used mysql on my computer for a lon...
Find the problem Today, when I tried to modify th...
Problem Description I created three virtual machi...
Label display mode (important) div and span tags ...
This article introduces how to create an index on...
1. Introduction I wrote an article before: The pr...
When you need to create an email in a shell scrip...
Table of contents 1. Project Integration 1. CDN i...