How come inactive links are still able to be clicked on?

I have been experimenting with various methods to disable links, but I seem to be unable to prevent them from being clickable. While I was successful in changing the cursor to 'not-allowed' when hovering over the disabled link, it still remains clickable. I've referenced resources like this one and this sample, but none of the solutions seem to work for me. Even after checking multiple sources, I can't figure out what I'm doing wrong.

 /***** entire navigation bar *****/
nav#prime {
  display: grid;
  place-items: center;
  font-family: "Gill Sans", sans-serif;
  font-size: 14.75px;
}
nav#prime ul {  
  grid-auto-flow: column;
  list-style: none;
  text-align: center;
  padding: 0;
  margin: 0;
}
nav#prime li { 
  margin: 0;
  padding: 0;
  position: relative;  
}

/***** links *****/
ul#navbar a:link
  Display:block;
  Text-decoration:none;
  Background-color:#0E0E10;
  Color:#FFFAFA;
  Margin:0;
  Padding:5px 11px;
}
ul#navbar a:visited {
  Background-color:#F5F5F5;
  Color:#1A1110;
}
... (CSS code continues)

<nav id="prime">
    <ul id="navbar">
        <li class="dropdown">
            <button type="button" onclick="myFunction()" class="dropbtn">The Desi Ghost Hunters
                <i class="caret-down"></i>
            </button>
            <ul class="sub-menu">
                <li class="suboption"><a href="#" title="Siddharth Bantval">Siddharth Bantval</a></li>
                ... (HTML code continues)

Answer №1

To achieve this, you can utilize the CSS property pointer-events: none;. This allows you to still trigger actions using event listeners, while disabling regular clicking functionality.

If you want to disable all mouse functions for a link, wrap it in a div tag and apply the cursor property as needed.

Check out the MDN documentation for the pointer-events property

/***** styling for navigation bar *****/

nav#prime a {
  pointer-events: none;
}

nav#prime {
  display: grid;
  place-items: center;
  font-family: "Gill Sans", sans-serif;
  font-size: 14.75px;
}
nav#prime ul {  
  grid-auto-flow: column;
  list-style: none;
  text-align: center;
  padding: 0;
  margin: 0;
}
nav#prime li { 
  margin: 0;
  padding: 0;
  position: relative;  
}

/***** styling for links *****/
ul#navbar a:link {
  display: block;
  text-decoration: none;
  background-color: #0E0E10; 
  color: #FFFAFA; 
  margin: 0;
  padding: 5px 11px;
}
ul#navbar a:visited {
  background-color: #F5F5F5; 
  color: #1A1110; 
}
ul#navbar a:hover {
  background-color: #242124; 
  color: #FFFFF0; 
}
ul#navbar a:active {
  background-color: #D3D3D3;
  color: #808080;
}

/***** styling for buttons *****/
button.dropbtn {
  outline: none;
  border: none;
  font: inherit; 
  background-color: #0E0E10; 
  color: #FFFAFA; 
  margin: 0; 
  padding: 5px 11px;
}

/***** submenu positioning *****/
#navbar ul {
  position: absolute;
  white-space: nowrap;
  z-index: 1;
  left: -99999em;
}

#navbar>li:hover>ul {
 
  position: absolute; 
  top: 100%;
  width: 100%;
  left: 0;
  background: #fff;
  border: 1px solid #000;
}

#navbar>li:hover>li li:hover>ul {
  left: 100%;
  margin-left: 1px;
}

/***** first tier *****/
#navbar {
  border: 1px solid;
  border-color: #0E0E10;
  border-radius: 4px;
  background-color: #0E0E10;
}
#navbar>li {
  float: left; 
}
<nav id="prime">
    <ul id="navbar">
        <li class="dropdown">
            <button type="button" onclick="myFunction()" class="dropbtn">The Desi Ghost Hunters
                <i class="caret-down"></i>
            </button>
            <ul class="sub-menu">
                <li class="suboption"><a href="#" title="Siddharth Bantval">Siddharth Bantval</a></li>
                <li class="suboption"><a href="https://www.ikerjimenez.com/" target="_blank" title="REAL NAME: Iker Jiménez Elizari">Iker Jiménez</a></li>
                <li class="suboption"><a href="#" title="Gaurav Tiwari">Gaurav Tiwari <span class="cross">&#8225;</span></a></li>
                <li class="suboption"><a href="https://www.youtube.com/channel/UC5RfSq8MS00LWofLPSKAnDA" target="_blank" title="Alberto del Arco">Alberto del Arco</a></li>
                <li class="suboption"><a href="#" title="Alexsander Myagchenkov">Alexsander Myagchenkov</a></li>
                <li class="suboption"><a href="http://chernobrov.narod.ru/" target="_blank" title="Vadim Chernobrov">Vadim Chernobrov <span class="cross">&#8225;</span></li>
                <li class="suboption"><a href="#" title="Meghna Porwal">Meghna Porwal</a></li>
            </ul>
        </li>
    </ul>
</nav>

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

Have you ever wondered why Vue 3 imports all JS files for every page upon the initial project load?

Is there a way to make Vue 3 import only the necessary js files for each component instead of loading all files at once when the project is first loaded? For example, if I navigate to the contact page, Vue should only import the contact.js file, rather tha ...

Is the mobile site displaying CSS pixels in the physical pixel resolution?

I am struggling to grasp the problem and finding it challenging to explain it clearly, so I have attached a picture depicting the issue. https://i.stack.imgur.com/E9Gzj.png My current approach involves using ratios of 100% and 100vw for element widths. D ...

Issue with Domsanitizer bypasssecuritytruststyle functionality on Internet Explorer 11 not resolving

CSS:- Implementing the style property from modalStyle in TypeScript <div class="modal" tabindex="1000" [style]="modalStyle" > Angular Component:- Using DomSanitizer to adjust height, display, and min-height properties. While this configuration work ...

Is it wise to use the<sup>attribute for mandatory form fields?

Would it be wise to utilize the <sup> tag instead of using margin-top: -xnumberofpx for indicating required fields in a form? <label for="address1" required>Address line 1<sup><img src="/src/images/requiredAsterix.png" width="10" heig ...

Navigating Your Way Through the Center (ASP.NET MVC)

My navbar has elements that I want to center within it, but using margin hasn't been successful. Do you have any suggestions on how I can achieve this alignment using CSS? This is the code snippet: <div class="navbar "> <div class="cont ...

Can a link be stored in a table using PHP?

I need assistance in organizing a page with a sidebar containing about 20 links as the code appears messy. Is there a way to store all <a href=.... in a table, an array, or another method for better organization? If anyone could provide an example, it ...

How to create a floating <Toolbar/> with ReactJS, Redux, and Material-UI

Can anyone help me figure out how to make a toolbar floatable when scrolling down using Material-UI? I tried setting textAlign:'center', position: 'fixed', top: 0, but it's resizing strangely when applied to the <Toolbar/>. ...

Troubleshooting Problems with Positioning and Floating in HTML and CSS

I'm facing some challenges with clearing floats (or it could be something else?). My goal is to have the #newsbar div free from the previous floats so that its width can extend 100% across the page/browser. I believe I've tried everything within ...

Developing a Form Submission Feature Using JQuery Mobile

I'm having trouble submitting a form using JQuery Mobile. Currently, my code looks like this: <form action="#pagetwo" method="post" name="myform"> <input type="text" name="myname"> <input type="submit" value="submit" /> ... and th ...

How can I showcase CSV data as clickable links and images on a website using HTML?

Looking for a way to display CSV file links as clickable hyperlinks in a table? Want to directly show images from photo links on your website as well? Wondering if this is even possible? Successfully showcased desired content in a table with the code prov ...

Populate the dropdown menu with data from a JSON file

Recently, I created a custom JSON file and wanted to populate a select>option using this data. However, I encountered an error message saying: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/.../p ...

Ways to conceal an element in Angular based on the truth of one of two conditions

Is there a way to hide an element in Angular if a specific condition is true? I attempted using *ngIf="productID == category.Lane || productID == category.Val", but it did not work as expected. <label>ProductID</label> <ng-select ...

Struggling with the development of a crossfading image gallery using jQuery's .animate() function while ensuring compatibility with IE8

Seeking assistance in creating a crossfading image gallery using jQuery and the .animate() function. I'm struggling to solve the issue of smooth fadeIn for the next image while maintaining compatibility with IE8. https://jsfiddle.net/Vimpil/fqhc1e9m/ ...

Is it deemed as an anti-pattern to establish directives for styling?

Currently, I am in the midst of developing a specialized component UI library for a specific project I'm involved in. This library will consist of unique stylized components with elements that are reused throughout. As I work on this project, I find ...

Combining the value of $(this) to create an identifier name

I am attempting to create a hover effect on an h1 element that triggers the glowing effect on a span element with an id that corresponds to the value of the h1. While I have successfully set up a glowing effect for a sentence, I am struggling to replicate ...

What steps can I take to ensure my CSS selector for the element is functioning properly?

Here is an example of some code: <html> <head> <style> .test{ background-color: red; p { background-color: yellow; } } </style> </head> <body> <div class="test"> ...

ImageMapster for perfect alignment

I'm struggling with centering a div that contains an image using imagemapster. When I remove the JS code, the div centers perfectly fine, indicating that the issue lies with the image mapster implementation. It's a simple setup: <div class=" ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each "qu ...

Error encountered in angular.forEach syntax

Can someone help me figure out why my array sum calculation using angular.foreach is resulting in a "syntax error" message? I believe my syntax is correct, as indicated by var sum += value.fare;. Any insights on why this error occurs would be appreciated. ...

JavaScript is not designed to run a second time

Currently, I have a script set up using $(document).ready(). It works perfectly upon initial loading. However, I also need this script to execute whenever the user changes an HTML select control. Ideally, upon page load, I want the filter and sort functio ...