Failure to Link Different Files Using HTML Links

Organizing the different pages of my website, I initially stored HTML files in a folder called X, with index.html, main.html, and other pages. To streamline access, I decided to separate the articles into folders A, B, and C within folder X. However, this led to issues with linking between the article pages as well as from the main pages to the articles.

For a clearer visualization of my problem, refer to the image below:

        <a class="active" href="Index.html" target="_blank">Home</a>
        <a href="#" target="_blank">Anime Stuff</a>
        <a href="Youtube.html" target="_blank">YouTube</a>
        <a href="Contact Me.html" target="_blank">Know Me</a>

https://i.sstatic.net/Ogeu3.png

Answer №1

Assuming that 'X' is your primary directory, any files located within it can be accessed as shown below:

<a href="./index.html">Index</a>
<a href="./contact.html">Contact</a>
<a href="./MainContent.html">Main Content</a>

For directories A, B, and C which are subdirectories of X, files can be accessed in the following manner:

For Directory A:

<a href="./A/index.html">Index</a>

For Directory B:

<a href="./B/index.html">Index</a>

For Directory C:

<a href="./C/index.html">Index</a>

Answer №2

Linking to Pages Within the Same Project Directory

For instance:

main-folder/
|—— home.html
|—— about.html
|—— contact.html

<a href="./about.html">About Us</a>

Answer №3

One efficient way to create links between these pages is by using URLs that are relative to your document root. For more information, you can refer to the discussion on Absolute vs relative URLs. By starting each URL with / (thus making them relative to the document root), navigation becomes much smoother.

For instance, imagine your Project Money directory as the document root, and let's assume it is accessed at . In this case, simply visiting or will lead you to the homepage. Similarly, accessing will direct you to the contact page, while will take you to the YouTube page. And for subdirectories, navigating to will bring up the article1.html page within the A directory.

To link to the article1.html page from anywhere else, you would use /A/article1.html as the href value. Similarly, linking back to the homepage from any location can be done using /index.html. Employing URLs relative to the document root ensures a cleaner method of linking pages compared to basing them on the current path (./A/article1.html, ./article1.html, article1.html, ../index.html, etc). Additional examples and resources can also be found in this post.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for aligning the navigation bar, main content, and footer in the center

Exploring the realm of web coding for the first time, I find myself in need of some guidance. My current project involves creating a webpage for the local sports team to replace their outdated one on Wordpress. Finding the platform not very user-friendly, ...

Issue with interactions between datepicker and jQuery dialog box

I am working with a datatable that displays user data, and each row has an edit button to open an edit form. I am opening this form using a jQuery dialog box and submitting it using ajax submit. However, when loading the form, the datepickers are not worki ...

How can I speed up the loading time of my background image?

I have noticed that my background image is loading slowly on my website. I expected it to be cached so that subsequent pages using the same background would load instantly. However, the background image is only loading once the entire page is drawn. My CS ...

The HTML5 audio player is experiencing technical difficulties on Internet Explorer

I'm having an issue with html5 audio not working on Internet Explorer. <audio id="beep-voice" controls autoplay style="opacity:0"></audio> Could someone please provide a solution? Thanks! ...

"Discover the power of regular expressions in manipulating YouTube shorts URLs using

I am currently creating a platform where users have the ability to share text, photos, and YouTube video links. I've been working on generating an embed URL from various types of YouTube URLs that are copied and pasted by users. A huge thank you to th ...

Resultant vector

Having trouble calculating the resultant of 3 vectors. Every time I input a number, it returns NaN. Can someone shed some light on this? var vector1 = document.getElementById("f1"); var vector2 = document.getElementById("f2"); var vecto ...

What is the best way to position two divs side by side while maintaining their individual padding?

When I remove the padding as shown, the website functions correctly with two div columns next to each other. However, upon adding padding, the #right div shifts downwards. How can I ensure it works as intended with padding included? HTML: Two divs direct ...

Failure to launch mail client from mailto attribute

Hey there! I'm currently diving into an HTML course on udemy, and there's this interesting part where the instructor showcases how a "mailto" attribute can be used to open a mail client upon clicking the submit button. I've followed all the ...

Javascript functions triggering repeatedly

I'm working on creating a fun trivia quiz using JavaScript functions. Each question involves globally defined functions called "right" and "wrong" that are supposed to update the score accordingly. However, I've run into an issue where the quiz s ...

Locate the parent element using a unique child element, then interact with a different child element

Can you help me come up with the correct xpath selector for this specific element? The element only has a unique href. Is it possible to locate the element by searching for the text iphone X within the href="#">iphone X and also checking for its paren ...

Updating the logic for reconnection when the connection is closed in MySql's X DevAPI can be achieved by utilizing the @mysql/xdevapi module

I am currently utilizing the X DevAPI of MySql v8.0.33 with the @mysql/xdevapi v8.0.33 package. Although I have implemented a reconnect logic, it doesn't seem to be functioning as expected. Here is the code snippet: const mysqlx = require('@mysq ...

displaying text next to an HTML image link on iOS devices

I am facing a situation where I need to display description text alongside images. Here is an example of what my description looks like: Test Article with Image and LinksTest Article with Image and Links<img alt="" src="http://stgen.eenaduindia.com/201 ...

Babel failing to transpile source code of npm link/symlink package

I am in the process of establishing a shared module environment using node. Below is an outline of my directory structure: project |--common | |--package.json | |--graphql | |----schema.js | |--server |--package.json |--serv ...

Ways to verify if fields within an Embedded Document are either null or contain data in Node.js and Mongodb

I need to verify whether the elements in the Embedded Document are empty or not. For instance: if (files.originalFilename === 'photo1.png') { user.update( { userName: userName ...

Can you explain the concept of Cross-origin requests?

My JavaScript application is designed to detect single, double right, and double left clicks. A single click triggers an asynchronous request to the HTTP server, while the rest are intended to change the user interface on the client side. However, I am str ...

Webpack 5 is unable to load animated gif files

Hello, I am currently diving into webpack and following the official documentation at https://webpack.js.org/guides/asset-management/#setup. My goal is to incorporate an animated gif using webpack 5. Although the placeholder for the gif is loading, I enco ...

Reducing image size using CSS can result in blurry images on multiple web browsers

Encountering challenges with downscaled images in multiple browsers... The images must be downscaled to adapt to the browser size. Here is the code snippet: #pic-holder img { -moz-transform: rotate(0deg); /*image-rendering:-webkit-optimize-contras ...

Toggle the tooltip to reveal a hidden div by clicking, and then click again to close it

I've been working on implementing a toggle div with a tooltip. The issue I'm facing is that the tooltip initially displays "Click to open", but after opening the toggle, it should change to "Click to close". Can someone assist me in achieving thi ...

Guide on displaying applicant name in the show route of your node.js/mongoDB application

Currently working on a website where applications are being accepted. In the admin panel, I want to display a list of all applicants and allow users to click on a name to view more information. However, I'm facing an issue where the same applicant is ...

Cannot work on repl.it; it seems to be incompatible with the freeCodeCamp - JavaScript Algorithms and Data Structures Projects: Roman Numeral Converter

Recently completed my Roman Numeral Converter and it functions correctly on repl.it. However, when testing it on freecodecamp, the output displayed: // running tests convertToRoman(2) should return "II". convertToRoman(3) should return "III". ... // tests ...