Html relative paths using period - html

I'm confused as to when the following are used and what they mean, for example in the src attribute of an img tag.
I know / means 'current directory' and ../ means 'up one directory'
. Current Directory? &lta href="." /&gt
./ Current Directory &ltimg src="./image.png" /&gt
/ Root directory &ltimg src="/image.png" /&gt
../ Up one directory &ltimg src="../image.png" /&gt
What is the difference between ./image.png and /image.png
Updated: / means root directory of the site

/ means starting from the root directory. Whereas ./ is the current directory, though I'm not sure there's any need for it (unless you're planning on appending to a PATH in Linux systems... happy to be wrong about that one).

./image.png will grab image.png relative to your current location. Calling ./image.png on domain.tld/site/page.html will look for the image at domain.tld/site/image.png
/image.png will look for the image in the root of your site. domain.tld/image.png
You could also use things like ../images/image.png. If this was used on domain.tld/site/page.html, the browser would load the image from domain.tld/images/image.png

The / means the root directory. Use . For the current directory.

Related

Root directory when linking css file to html file

While learning about paths I found out that "/" takes you to the root directory. I made .html and .css files in the same directory to test how it behaves for different paths. When linking the css file, href = "app.css" and href = "./app.css" both work fine but when I try href = "/app.css" it doesn't link. I know "/" is suposed to take you to the root directory and from what I understand the directory of the html file is the root directory. So why isn't the css file linking properly?
/ means the root of the current drive
./ means the current directory
../ means the parent of the current directory
No need to add the "/" or "./" because your app.css file is in your current directory.

What does "./" do in href?

I know that for example:
../path/to/file.html
does first jump from the current directory to the next higher directory and then enters
path/to/file.html
However what does
./path/to/file.html
do? I couldn't find an answer on the net so far :(
./ or . is ALWAYS the current directory.
~/(on Linux) is the current user's home directory.
For you to know as well: cd %userprofile% (on Windows) sends you to home user directory
Imagine I you're in repository2 and you want to include the file.txt:
~/ ---> Pictures
---> Documents --> repository1 --> repository2
---> Downloads
---> file.txt
You simply do:
../../file.txt
or
~/file.txt
And Imagine you want to move the file.txt to the current repository:
mv ../../file.txt .
. is a reference to the current directory. See: Path (computing)

How to use logic path in web site

I have a website:
www.mydomain.com/panel/abcde.html
I don't remember the difference between ./ and ../
./ is used to return in the first level?
Instead ../ is used to simulate all domain?
.../ exists?
I believe it is like this :
/ = root of the currently location
./ = current directory
../ = parent of current directory
Reference could be found here
/ is the root folder of the filesystem.
./ usually denotes the current folder that your program or script is in, usually the same one with the file you run.
../ denotes the folder above the current one.
.../ Does not exist. If you type that on terminal, it will throw error No such file or directory

Difference between "../" and "~/" relative path

I am storing style sheets in {root}/styles while images in {root}/images for a website.
what is difference between ../ and ~/. ?
../ references the parent directory.
~/ has no special meaning in standard URLs. It does have special meaning in
ASP.NET where it references the root of the application
UNIX shells where it references the current user's home directory
../ is relative to the current path of the file.
~/ is relative to the root of the application (in ASP.NET).
../ goes up one dir from the current dir.
~/ goes to the dir where you originally came from (not usable in html).
Depends on the framework you are working on.If you have ASP.NET context ~/with ResolveUrl refers to the root level directory, ignoring the sub directories as well.
In CSS we navigate to the previous directories using ../. If you use ../../ you navigate to two steps back and so on.If you use ./, you can reach to the root

Root Directory?

I'm editing a file in a folder in my root directory.. here's a quick tree:
root
- images
- m
- - index.php
If I want to grab the images folder from index.php, how would I go about doing that? I've tried:
../images
I want to eliminate having to use my website URL.
you should use /images instead of ../images if you know the image directory is in the root. this will resolve to a directory named images in the root from any path.
eg if you are on page /pages/html/MyPage.html the path /images will still resolve to the images directory in root whereas ../images would resolve to /pages/images.