Issue with the relative link not functioning

Currently, I am in the process of working on a project that involves the use of bootstrap. As part of this project, I am configuring a navigation bar. Here is the code snippet for one item in my navigation bar:

<li class="active"><a href="/aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

However, upon loading the index.html file, instead of directing to 'C:/Users/.../about.html', it redirects to 'file:///C:/aboutus.html'. This results in a 404 error.

To resolve this issue, I made the following change to the code:

<li class="active"><a href="../project/aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

After making this adjustment, the link now points to the correct location, allowing me to access the page successfully.

Can you explain why this modification was necessary?

Edit: Just to clarify, I am running the project locally, and the same issue occurs with every file within the file system. The file structure is as follows:

../project/aboutus.html
../project/index.html
../project/css/ (contains standard bootstrap files)
../project/fonts/ (contains standard bootstrap files)
../project/js/ (contains standard bootstrap files)

Edit2: Adding just a single dot before the relative path also resolves the issue. For example:

<li class="active"><a href="./aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

Answer №1

If a link starts with "/", it is considered an absolute path. To resolve this, simply remove the forward slash. Check out this example:

<li class="active">
    <a href="aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a>
</li>

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

Do all HTML elements support any CSS rule and are they all capable of being inherited?

Are there any restrictions on applying specific CSS rules to certain HTML elements, or can any valid rule be used on any element? Is it legal to apply any valid CSS rule to any HTML element? Can any rule be inherited? What is the inherited value, particu ...

Interactive YouTube video in a responsive classroom environment

Hello! I have a website at bit.ly/1EfgOsM and I am trying to align the video box with a YouTube video next to an image box. The width of the image box is set to 40%, so I want the video box to also be responsive with a width of 40%. The video box is in a s ...

Unlocking two features with just a single tap

I am currently working on a website for a kiosk, where the site transitions like a photoslide between each section. To achieve this effect, I have added a layover/mask on the initial page. The layover/mask is removed using a mouse click function. This is ...

The precedence of theme CSS is paramount

Check out this link for Smirnoff Espresso Vodka 70cl (password: hide) Upon inspecting the page source, you'll see that my main stylesheet (main-style) is loaded at the top of the head section with high priority, even above my theme's style. Why ...

How to adjust the size of list-style-image in CSS

How can I set custom SVG icons with CSS on a <ul>'s list items? See below: <ul> <li style="list-style-image: url('first.svg')">This is my first item</li> <li style="list-style-image: url('second.svg&a ...

What is the best way to incorporate a gratitude note into a Modal Form while ensuring it is responsive?

Currently, I have successfully created a pop-up form, but there are two issues that need fixing. The form is not responsive. After filling/submission, the form redirects to a separate landing page for another fill out. Expected Outcome: Ideally, I would ...

JavaScript - Removing Content from an Element

I have a coding script that adds an image preview of uploaded images. The issue I am facing is that the previous image does not clear when the form is filled out again. The id of the div where thumbnail images are being displayed is "thumbnail". Can someo ...

Adding list elements within a bootstrap `<li class="list-group-item"> using JavaScript is a simple process

Bootstrap is giving me trouble when I try to add a list. The list ends up outside of my Bootstrap code instead... Here is the image of the output I am seeing: https://i.sstatic.net/XhXAw.png My Code: var title = document.getElementById('title&ap ...

Creating a custom tab bar using jQuery Mobile

I transferred a tab bar from one of my projects to jsfiddle, but the CSS was too complex to understand. So, I extracted useful code from the CSS and created my own version in this new fiddle. However, it looks exactly like the example. Now, I need to imple ...

To include a slash or not before the assets path in HTML - that is the question

Should the use of / in front of paths in HTML pages be considered a good practice? If using / for paths, is it necessary to configure a <base url=""> in the page? An issue arises with a generated CSS file that includes the following: background-ima ...

Tips for adjusting an svg component to suit various screen sizes

I inserted the following SVG component into my HTML file. It fits perfectly on my tablet, but it's too large for my smartphone. How can we automatically adjust the size of the SVG to fit different screens? <svg viewBox="310 -25 380 450" w ...

The "flickering" effect of the div is like a dance, moving gracefully between fade outs and

I am encountering a similar issue as described in this thread: same problem (fiddle: original fiddle). However, I am still learning JavaScript and struggling to apply the solution provided because my HTML code is slightly different. Can someone please assi ...

When you hover over nested HTML-lists in a webpage, make the tree's long text lines expand gracefully using a combination of HTML, CSS

In my Angular 4 application, I have a left div that displays a tree of items as recursive HTML lists. When there is a long text, it gets cut off by the border of the div and a scrollbar appears. I want to have the text expand beyond the border and show in ...

Creating an HTML table from an array using PHP and MySQL

Currently, I am working with 2 tables in a database and using PDO to join them together. The output is in one table format, but I need it to be displayed in a different layout. Do I require some sort of dynamic pivot? The structure of the two tables is as ...

Eliminating the blank space at the top of the page

I am seeking guidance on how to eliminate the blank space above my login page. I cannot pinpoint exactly where this space is originating from. When I integrated a login page into my MVC project, I noticed an empty space at the top of the page that I want t ...

Attempting to upload a file into the system

I'm in the process of creating a website that allows for file uploading. Check out my code below: index.php: <?php include('/inc/header.php'); ?> <?php if($_SESSION['username'] != null) { echo " <form class=&bs ...

Is there a way to prevent the removal of CSS files from a module when deploying a Next JS API to Vercel?

Is there a way to access a css file from a node_modules package in order to generate swagger documentation within an endpoint using the Next API? I have noticed that tree shaking is removing the css files from the swagger-ui-dist package. How can this be ...

How to style a div's height responsively behind a circle using CSS

Can a CSS pattern be created with responsive design, ensuring that the background line is always in the correct position and height regardless of window size? https://i.sstatic.net/27Tf2.jpg ...

setTimeout executes twice, even if it is cleared beforehand

I have a collection of images stored in the img/ directory named 1-13.jpg. My goal is to iterate through these images using a loop. The #next_container element is designed to pause the loop if it has already started, change the src attribute to the next im ...

JSON data not displaying correctly in bootstrap table

I've been grappling with this issue for hours now, but I'm struggling to get my bootstrap table populated correctly. Here's the snippet of my HTML: <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.1 ...