HTML relative path and absolute path

Source: Internet
Author: User
Tags file info

If you are referencing a file (such as adding a hyperlink, or inserting a picture , etc.), the wrong file path is used.

Will invalidate the reference (the linked file cannot be browsed, or the inserted picture cannot be displayed, etc.).

To avoid these errors and to properly reference the file, we need to learn the HTML path.

HTML has 2 ways of writing: relative and absolute paths.

HTML relative path (Relative path) file reference for the same directory

If the source and reference files are in the same directory, write the reference file name directly.

We are now building a source file info.HTML, in info.HTMLTo quote index.HTMLFile as a hyperlink.

Suppose info.HTMLThe path is: C:\Inetpub\wwwroot\sites\blabla\info.HTML

Assume index.HTMLThe path is: C:\Inetpub\wwwroot\sites\blabla\index.HTML

In info.HTMLJoin index.HTMLof hyperlinksCodeIt should be written like this:

    1. <a href = "index. HTML">index. HTML</a>
Copy Code

How to represent a parent directory

.. /indicates the directory where the source file is located, at the top level of the directory. /.. /represents the upper parent directory of the directory where the source file resides, in such

Push.

Suppose info. The HTML path is: C:\Inetpub\wwwroot\sites\blabla\info. HTML

Assume index. The HTML path is: C:\Inetpub\wwwroot\sites\index. HTML

In info. HTML joins index. The code for the HTML hyperlink should read like this:

    1. <a href = ". /index. HTML">index. HTML</a>
Copy Code

Suppose info. The HTML path is: C:\Inetpub\wwwroot\sites\blabla\info. HTML

Assume index. The HTML path is: C:\Inetpub\wwwroot\index. HTML

In info. HTML joins index. The code for the HTML hyperlink should read like this:

    1. <a href = ". /.. /index. HTML">index. HTML</a>
Copy Code

Suppose info. The HTML path is: C:\Inetpub\wwwroot\sites\blabla\info. HTML

Assume index. The HTML path is: C:\Inetpub\wwwroot\sites\wowstory\index. HTML

In info. HTML joins index. The code for the HTML hyperlink should read like this:

    1. <a href = ". /wowstory/index. HTML">index. HTML</a>
Copy Code

How to represent a subordinate directory

Refer to the Subordinate directory file, directly write the path of the subordinate directory file.

Suppose info. The HTML path is: C:\Inetpub\wwwroot\sites\blabla\info. HTML

Assume index. The HTML path is: c:\Inetpub\wwwroot\sites\blabla\html\index. HTML

In info. HTML joins index. The code for the HTML hyperlink should read like this:

    1. <a href = "html/index. HTML">index. HTML</a>
Copy Code

Suppose info. The HTML path is: C:\Inetpub\wwwroot\sites\blabla\info. HTML

Assume index. The HTML path is:

C:\Inetpub\wwwroot\sites\blabla\HTML\tutorials\index. HTML

In info. HTML joins index. The code for the HTML hyperlink should read like this:

    1. <a href = "html/tutorials/index. HTML">index. HTML</a>
Copy Code

HTML absolute path (Absolute path)

HTML absolute path (Absolute path ) refers to the full path of the file with the domain name.

Assume that you have registered the domain name xinran001.com , and you have applied for a virtual host, your virtual hosting provider gives you a directory, such as WWW, This www is the root directory of your .

Assume that you have placed a file at the WWW root index. html , the absolute path to this file is:

http://www.xinran001.com/index. , the absolute path to this file is

http://www.xinran001.com/bbs/index.php .

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.