Deactivate the ability to focus on navigation links permanently

Having a similar issue to this one. I am trying to remove the focus feature from links in the navigation bar. The links:

<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
  <li><a href="#" class="nav-link px-2 active">First</a></li>
  <li><a href="#" class="nav-link px-2">Second</a></li>
</ul>

I've tried using the outline style to disable this feature:

<style>
  .nav-link {
    color: #888888;
  }
  .nav-link:hover {
    color: black;
  }
  .nav-link:focus {
    outline:none;
  }
  .active {
    color: black;
  }
</style>

However, it is still displaying the unwanted blue effect: https://i.sstatic.net/05kvx.gif

I don't want to change the color of the focus effect as neither black nor #888888 would be appropriate in my case. I simply want to disable this behavior. It seems to be related to .nav-link:focus because changing outline:none; to color:red; changes the focus effect to red.

Things I have attempted include:

outline: none;
outline: 0;
outline: 0 !important;
outline: 0 none !important;

The complete header code (after applying color: initial and outline: thin dotted;):

.nav-link {
  color: #898989;
}
.nav-link:hover {
  color: black;
}
.nav-link:focus {
  outline: thin dotted;
  text-decoration: none;
  color: initial !important;
}

.active {
  color: black;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385a57574c4b4c4a5948780d160b160815595448505909">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

<header class="p-3 text-bg-light">
<div class="container">
  <div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">

    <ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
      <li><a href="#" class="nav-link px-2 active">First</a></li>
      <li><a href="#" class="nav-link px-2">Second</a></li>
    </ul>

  </div>
</div>
  </header>

Answer №1

In my opinion, the problem can be resolved by setting the color to initial in the focus state:

.nav-link:focus {
    color: initial
}

To learn more about resetting default browser styles for the anchor element, check out this helpful response from a previous question.

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

Transformation of HTML occurs in React components upon saving in Visual Studio Code

As I embarked on my journey to learn React, I hit a roadblock early on. Searching for a particular setting, I somehow ended up selecting something different, like NodeJS. Now, the issue at hand is: Behold the First Image: https://i.sstatic.net/ETmDk.png ...

Styling HTML elements using CSS within PHP echo statements

I am a beginner when it comes to PHP and I'm trying to figure out how to style this table. I tried creating a class, but changing the styles in a separate CSS file didn't work for me. Should I use style tags? How should I go about styling this? ...

Issue with font-size changes using css variables in Angular not updating in browser for specific fields

Utilizing CSS variables, I have implemented a feature that allows users to adjust the font size to small, medium, or large. While this functionality works correctly for most fields, there are certain instances where the value is applied but not displayed. ...

What could be the reason for the lack of definition of the `pieceOfText

My latest project involves a fun guessing game centered around decrypting text, but I've hit a snag with a variable in my JavaScript code. This variable, known as pieceOfText, should be assigned a random piece of text from an array containing 3 encode ...

PHP code for sending email with attachment file

I have created an HTML form with the option to upload a file and send it to me via email. Additionally, I already have a PHP script that sends textbox values and text area values via email. Now, I would like the uploaded file from the form to be sent to m ...

one webpage featuring HTML-based charts - visual data representation in HTML

I am looking to create HTML charts using a single file that includes JavaScript and jQuery. Specifically, I need the ability to generate line charts, pie charts, and other types of graphs, all within one file. I do not have much knowledge about JavaScript ...

How can I place a Pure CSS Menu within a Div Container?

I've been experimenting with the Pure CSS menu found on this site: http://csswizardry.com/2011/02/creating-a-pure-css-dropdown-menu/ It's working well, but I'm facing an issue where I want to place this menu inside another div container. H ...

How to display a "data not available" notification in AngularJS ngTable plugin tables when the data response array is void of content

I need to implement a no data message in my ngTable table when the response data array is empty. Currently, I have the following code: <tr ng-repeat="row in $data"> <td data-title="'name'" filter="{name: 'text& ...

Unsuccessful passing of the popstate event in jQuery bind

Currently, I am working on a small demo using the History API, but I seem to be facing some challenges: $(window).bind('popstate', function(event) { console.log('pop: ' + event.state); }); When I click on the 'P ...

Exploring the efficiency of different CSS selectors

I am struggling with the following code: HTML: <ul class="list"> <li class="list-item"> item 1 </li> <li class="list-item list-item_active"> Active item </li> <li class="list-item"> item 3 </li> ...

Two rectangular divisions placed next to each other, with one perfectly centered and the height of the second division adjusting to match the height of the

I attempted to implement the Matthew James Taylor method, utilizing three columns. However, my main issue arises when I desire the middle column to dictate the height. In other words, if the center div is 500px in height, I want the right div's height ...

Out of these two selectors, which one performs better?

Examining the code snippet below: <ul> <li> <a ... Between these two stylesheets which would be more efficient with the same declarations? if any performance gains were to be observed. ul { font-size: 1.25rem } ul a { font-siz ...

CSS Animations as an Alternative to jQuery's fadeIn(), fadeOut(), and fadeTo() Functions

I currently have the following code snippet: $('#button1').click(function(){ $('#header_bg').fadeTo(15, 0, function() { document.getElementById('header_bg').style.fill = '#FF0000'; }).fadeTo(&ap ...

What is the best way to align this in the middle on iOS?

Screenshot Greetings, I am facing an issue with centering an element on Apple devices. In the screenshots provided, you can see how it appears on iOS, Android, and a Windows PC. Despite trying various methods, I have been unable to solve the problem. Can ...

merge various CSS styles into a single one

My div has a mix of styles applied to it. <div class="alert alert-secondary login-alert" role="alert">Please contact the administrator to receive credentials!</div> The styles alert and alert-secondary are default styles from bootstrap 4, whi ...

The expression `Object.prototype.toString.call(currentFruit) === "[object Date]"` checks if the object referenced by `current

Hi, I'm just starting to learn JavaScript and I have a question about an if condition that I came across in my code. Can someone please explain what this specific if condition does? Object.prototype.toString.call(currentFruit) === "[object Date]& ...

Having difficulty linking a subclass in HTML with CSS

<div class="section-3"> <div class="section-3a"> <div class="section-3a(a)"> <p>light background color (header and sidebar)</p> </div> <div class="section-3a(b)"> <p>#FFFFFF</p> ...

Disable a button during an AJAX request

Whenever a button is clicked, the record is saved to the database without refreshing the page using AJAX. I have implemented the AJAX code successfully. Now I need guidance on how to manage the state of the Submit button - enabling/disabling it dynamicall ...

Menu Selector on the Right Side

I am currently working on a drop down menu and trying to align it to the right using HTML and CSS. Below is an example that I have been referencing: http://codepen.io/anon/pen/RNLmvq Attached here is a screenshot of how the menu appears without the text ...

"Scroll the menu to the specified location X pixels above the targeted div

Trying to explain may be a bit tricky, but please bear with me. I have this script that allows my menu to scroll to divs on my single-page website: $(document).ready(function(){ $('a[href*=#]:not([href=#])').click(function() { if (lo ...