How to link html pages in same or different folders? - html

How can I link to html pages if they are in same or different folders without writing full path?

Within the same folder, just use the file name:
my link
Within the parent folder's directory:
my link
Within a sub-directory:
my link

Also, this will go up a directory and then back down to another subfolder.
link
To go up multiple directories you can do this.
link
To go the root, I use this
link

In addition, if you want to refer to the root directory, you can use:
/
Which will refer to the root. So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:
My Index Page
Robert is spot-on with further relative path explanations.

You can go up a folder in the hierarchy by using
../
So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:
Link to My Page

use the relative path
main page might be:
/index.html
secondary page:
/otherFolder/otherpage.html
link would be like so:
otherpage

If you'd like to link to the root directory you can use
/, or /index.html
If you'd like to link to a file in the same directory, simply put the file name
Employees Click Here
To move back a folder, you can use
../
To link to the index page in the employees directory from the root directory, you'd do this
Employees Directory Index Page

I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!
eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!

Short answer:
. is for current directory
.. is for upper directory as in cd .. command on shell.
Simple yet tricky, I write this answer primarily for myself not to forget next time.
ademSite/
├── index.html
└── style.css
The link to CSS in index.html:
<link rel="stylesheet" href="style.css"> or
<link rel="stylesheet" href="./style.css">
ademSite/
├── index.html
└── stylefiles
└── style.css
This case it should be:
<link rel="stylesheet" href="stylefiles/style.css"> or <link rel="stylesheet" href="./stylefiles/style.css">
├── html
│   └── index.html
└── stylefiles
└── style.css
In this case path must be:
<link rel="stylesheet" href="../stylefiles/style.css">

Use
../
For example if your file, lets say image is in folder1 in folder2
you locate it this way
../folder1/folder2/image

href="./page.htm" for the same directory
href="../page.htm" parent directory
href="~/page.htm" root directory or the upper most dir.

Answer below is what I created to link html contents from another shared drive to the html page I would send out to managers. Of course, the path is relative to your using, but in my case, I would just send them the html, and everything else that is updated from load runner dynamically would be updated for me.
Saves tons of paper, and they can play with the numbers as they see fit instead of just a hard copy this way.
SRC="file://///shareddrive/shareddrive-folder/username/scripting/testReport\contents.html" NAME="contents_frame" title="Table of Contents"

For ASP.NET, this worked for me on development and deployment:
<a runat="server" href="~/Subfolder/TargetPage">TargetPage</a>
Using runat="server" and the href="~/" are the keys for going to the root.

This worked for me <a href="preferedfile name.html">to be clicked <a/>

When I Was creating a webpage, I found out that With moving Html files to different Folders, It changes the paths of the images, videos, music, PDF files, etc. With them, you have to go out of the file the HTML is located in, with the
../HTML. Then when your out, depending on where your page content is, insert,
Chipmunk Memes
*/ This is where the HTML is located ^^^^^^ */
<img class="demo cursor" src="../6.png" width="100" height="50" onclick="currentSlide(6)" alt="Sasha Having Some Fun">
*/ This is where the images are located. The "../6.png" is the image file, and it is located one directory back. */

Related

How do I link to a CSS file that is in another folder, from within a subfolder?

I am working on programming a very basic show streaming site for a project, and I have multiple folders. Folders include:
HTML
CSS
Shows
Inside of the "Shows" folder, I have a subfolder called "Testshow".
How do I link a CSS file from the CSS folder into an html file in the Testshow folder?
I have tried
<link rel="stylesheet" href="/css/style.css">
and some other things, but nothing has been working.
try something like this from your html file ../css/style.css
../ it means one folder up
../../ it means two folder up
Thank you #Konstantin Savusia !
I used ../ before asking and it didn't work, but what you recommended did work!
I just added ../../ to the beggining.

CSS background-image not loading

I am having an issue getting my background-image to load as a live website (using github pages). When i load it locally I can get it to work by entering in the full directory. However when I then move it to Github the directory changes and so it no longer works. To summarise, when I use background-image url("images/picture.jpg"); it will not work at all. I have to type in background-image url("c/onedrive/webroot/images/picture.jpg"); so the whole file name. However that does not work when put onto Github. Any help would be much appreciated. (:
As others mentioned, it seems like a file path issue. When using relative paths like images/picture.jpg, make sure the target image is in the correct relative location as indicated. If your images folder is located at the project root, your background-image url had safer/better be /images/picture.jpg with the / at the beginning to denote the project root.
Update
Looking at your code on the repo, I fixed it by updating the relative path — background-image: url("../images/abstract.jpg");
Your folder structure looks like...
/
|
├── css/
├── images/
├── js/
├── objects/
└── video/
Since your stylesheet in css folder is pointing to a file in images folder, you'd need to use a correct relative path.
I have faced this problem before. If you're background-image doesn't work check if your path is correct you could also right click the image in the file browser open Properties
--> Security and copy the path from there. If this doesn't work copy the image address directly from the browser and paste it there.
Check your path is correct
body {
background-image: url("path_of_image_from_this_page.jpg");
}

How to reference external css file in file manager - Domain.com

I'm having trouble referencing an external css file in my file manager. My html page is in a folder called "homepage" and my css file is in a folder called "library".
Currently, I have
<link rel="stylesheet" href="library/homepagecss.css">
but that won't reference the css file.
My only option is to have the homepage html file and css file in the same folder but i'd like to have them separated for organization.
Anyone know how to do this in Domain's file manager?
You should either write an absolute path there, like
<link rel="stylesheet" href="C:/User/Documents/public_html/library/homepagecss.css">
(I am assuming your path to the current directory)
BUt if I understood well your both folders library and homepage are in the same folder called public_html you can try this one
<link rel="stylesheet" href="../library/homepagecss.css">
By entering .. you go up in the directory tree, you go up at the parent directory, and you need to go up at public_html cause there is where you library folder is located.
If the homepage of your site is at example.com, and your homepage is in a “homepage” folder, then the href you currently have is going to be looking for a file at example.com/homepage/public_html/library/homepagecss.css. And that’s obviously not correct.
You have two options to fix it.
Use an absolute path to the CSS file: href="http://example.com/library/homepage.css"
Use the HTML <base> tag to set your base path as your homepage in the <head> of your site, and then specify the relative URL in the link to your stylesheet: href="/library/homepagecss.css"

How to link a HTML page to a CSS file when the CSS file is in an upper directory?

There is my problem:
Since I had some organization issues with my website, I wanted to arrange my files to a better classification.
Now, the folder tree looks like:
www
ressources
images
...
css
design.css
mypage1
index.html
mypage2
index.html
index.html
And now I don't know how to link the css file to the pages stored in a folder like the "mypage1" folder.
To start from my C: drive will will produce path errors once online, I tried the "shortcuts to the css file in each folder" solution too, but I think there is a far better way to proceed.
Need some help!
Thanks again!
use the link:
<link type="text/css" rel="stylesheet" href="../ressources/css/design.css">
here, used ../ going back folder..
You can use:
<link rel="stylesheet" href="../ressources/css/design.css" type="text/css" media="all">
The .. will go one directory top. Since the html files are in a directory (like mypage1), this will go to the parent directory, which is www. Then the next that should be done is to pass the directory path to your CSS file, which in your case is /ressources/css/design.css.

Having links relative to root?

Is there a way to have all links on a page be relative to the root directory?
For example, on www.example.com/fruits/apples/apple.html I could have a link saying:
Back to Fruits List
Would this link be pointing to www.example.com/fruits/apples/fruits/index.html or www.example.com/fruits/index.html? If the first, is there a way to have it point to the 2nd instead?
A root-relative URL starts with a / character, to look something like link text.
The link you posted: Back to Fruits List is linking to an html file located in a directory named fruits, the directory being in the same directory as the html page in which this link appears.
To make it a root-relative URL, change it to:
Back to Fruits List
Edited in response to question, in comments, from OP:
So doing / will make it relative to www.example.com, is there a way to specify what the root is, e.g what if i want the root to be www.example.com/fruits in www.example.com/fruits/apples/apple.html?
Yes, prefacing the URL, in the href or src attributes, with a / will make the path relative to the root directory. For example, given the html page at www.example.com/fruits/apples.html, the a of href="/vegetables/carrots.html" will link to the page www.example.com/vegetables/carrots.html.
The base tag element allows you to specify the base-uri for that page (though the base tag would have to be added to every page in which it was necessary for to use a specific base, for this I'll simply cite the W3's example:
For example, given the following BASE declaration and A declaration:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Our Products</TITLE>
<BASE href="http://www.aviary.com/products/intro.html">
</HEAD>
<BODY>
<P>Have you seen our Bird Cages?
</BODY>
</HTML>
the relative URI "../cages/birds.gif" would resolve to:
http://www.aviary.com/cages/birds.gif
Example quoted from: http://www.w3.org/TR/html401/struct/links.html#h-12.4.
Suggested reading:
http://www.motive.co.nz/glossary/linking.php
http://www.communitymx.com/content/article.cfm?cid=AEDCC52C4AD230AD
Use
Back to Fruits List
or
Back to Fruits List
If you are creating the URL from the server side of an ASP.NET application, and deploying your website to a virtual directory (e.g. app2) in your website i.e.
http://www.yourwebsite.com/app2/
then just insert
<base href="~/" />
just after the title tag.
so whenever you use root relative e.g.
<a href="/Accounts/Login"/>
would resolve to "http://www.yourwebsite.com/app2/Accounts/Login"
This way you can always point to your files relatively-absolutely ;)
To me this is the most flexible solution.
Back to Fruits List
Relative Path Summary (applicable to href, src etc.,):
/file_Or_FolderName Root directory
./file_Or_FolderName Current directory
../file_Or_FolderName Previous directory (One level up)
../../file_Or_FolderName Previous of previous directory (Two levels up)
../../../file_Or_FolderName Just like above - Three levels up
Example:
www.example.com
├── apple.html
└── FolderA
├── fileA.html
└── FolderB
├── fileB.html
└── FolderC
├── fileC.html
└── FolderD <------ Suppose you're here (current directory)
├── fileD.html
└── FolderE
└── fileE.html
Following shows how to access the file at different levels using the relative path (applicable to href, src etc.,)
fileD.html - same level access(or)
./fileD.html - same level
./FolderE/fileE.html - 1 level Down
../fileC.html - 1 level Up
../../fileB.html - 2 levels Up
../../../fileA.html - 3 levels Up
../../../../apple.html - 4 levels Up (or)
/apple.html - 4 levels Up but direcly using root /
To give a URL to an image tag which locates images/ directory in the root like
`logo.png`
you should give src URL starting with / as follows:
<img src="/images/logo.png"/>
This code works in any directories without any troubles even if you are in branches/europe/about.php still the logo can be seen right there.
Use this code "./" as root on the server as it works for me
Back to Fruits List
but when you are on a local machine use the following code "../" as the root relative path
Back to Fruits List