How to use relative path in HTML using /

Asked

Viewed 888 times

0

Hello, I have a question about relative path in html, I know how to use (../) and (./) only I am not able to understand how to use only (/) I have researched several times and also tried several ways to use in my projects and could not use if someone can give me a very simple example was very grateful!

3 answers

1

Leandro,

The / is the root directory and therefore requires absolute path. That means it is the directory that contains everything! Therefore, to utilize it, you need to provide the whole path - from root to file itself.

Look at this another answer for more information on relative and absolute directories.

0

The difference is as follows:

  • /: Root directory;

  • ./: Current directory;

  • ../: A directory above the current one, example www.dominio.com/meuprojeto/ the directory used is the www.dominio.com/;

  • ../../: Two directories above the current one (and so on)

0

Let’s say you’re accessing the site www.meudominio.com/dirA/dirB if there is a link to this page / will make you go back to the www.meudominio.com/ which is the root directory, the same applies when including imagens, scripts if you in a subfolder put /meuscript.js it will look at the root or be www.meudominio.com/meuscript.js

Another example:
You have a page index.html inside www.meudominio.com/dirA/dirB on it you want to include a javascript called script.js which is also in the same directory:

With absolute path inclusion would thus be

<script src='/dirA/dirB/script.js'></script>

With relative path inclusion would thus be

<script src='./script.js'></script>

Another answer which may also be useful

Browser other questions tagged

You are not signed in. Login or sign up in order to post.