There seems to be an issue with the fixed navigation menu in Bootstrap 4. I seem to be overlooking something that is causing this problem

I encountered an issue with my fixed navigation while using bootstrap 4. Everything works fine when hovering over non-active nav items, but it displays two bottom borders when hovering over the active nav item. I'm seeking assistance to resolve this issue. Thank you.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>My Blog</title>
    <!-- bootstrap.min.css -->
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <!-- google fonts -->
    <link href="https://fonts.googleapis.com/css?family=Handlee" rel="stylesheet"> 
</head>

<body data-spy="scroll" data-target=".navbar">

<div class="container-fluid ">
    <nav class="navbar fixed-top mainNavigation navbar-expand-lg navbar-light bg-light">
          <a class="navbar-brand" href="#">Next World</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#homeNav" aria-controls="homeNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>

          <div class="collapse navbar-collapse" id="homeNav">
            <ul class="navbar-nav mr-auto ">
            </ul>
            <ul class="navbar-nav">
                  <li class="nav-item active">
                  <a class="nav-link" href="#home">Home <span class="sr-only">(current)</span></a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" href="#about">About Us</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" href="#team">Our Team</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" href="#product">Our Product</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" href="#services">Our Services</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" href="#contact">Contact Us</a>
                  </li>
            </ul>
          </div>
    </nav>  
</div>  


<!-- other -->
<div id="home" style="height: 500px;">Home</div>
<div id="about" style="height: 500px;">About</div>
<div id="team" style="height: 500px;">Team</div>
<div id="product" style="height: 500px;">Product</div>
<div id="services" style="height: 500px;">Services</div>
<div id="contact" style="height: 500px;">contact</div>
    <!-- jquery link -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <!-- popper.js -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <!-- bootstrap.min.js -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>

CSS code snippet:

.mainNavigation{
    background-color: #fff !important;
    font-family: 'Handlee', cursive;
    font-size: 16px;
}
.nav-link{
    color: rgb(165, 29, 43) !important;
}
.navbar-nav .nav-item{
    padding-top: 1px;
    cursor: pointer;
    }
    .navbar-nav .nav-item{
        opacity: 0.5;
    }
    .navbar-nav .nav-item:hover {
        opacity: 1;
        border-bottom: solid 2px rgb(165, 29, 43);
        padding-top: 0px;
        border-radius: 1px;
        transition-delay: 0.2s;
    }
  .navbar-nav .nav-item .active {
        opacity: 1;
        border-bottom: solid 2px rgb(165, 29, 43);
        padding-top: 0px;
        border-radius: 1px;
        transition-delay: 0.2s;
    }

You can also view the code on: https://jsfiddle.net/de_pes08/k12vgu3q/

Answer №1

To address this issue, you can implement a straightforward CSS solution. Simply create a logic that states: when hovering over a list item denoted by the class .nav-item, the active link (.nav-link) should not display an additional bottom border.

The CSS code to achieve this effect would be:

  .nav-item:hover a.nav-link.active {
    border: none;
}

Keep in mind that when testing this CSS live, you may notice a slight delay in the display of the active list element compared to others. To eliminate this delay, you can remove the transition-delay property from your primary CSS file.

Thank you.

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

Is the contenteditable feature working properly when updating PHP, SQL, and AJAX in the network?

Struggling with updating modified text to SQL using PHP and Ajax. Unsure if the issue lies in the data sent through Ajax or a problem within the PHP script. Below is my snippet from the HTML file: <tr> <td class="editingTab" contenteditable=&ap ...

hover causing the table cell to act erratically

My table consists of three cells with widths of 30%, 40%, and 30% respectively. The table itself occupies 25% of its container, which can range from 1024px to 400px. The first cell contains a button labeled GALLERY. Upon hovering over the cell, the text c ...

Tips for maintaining the full width/height ratio of a child image when covering a fixed size container

I have a square container with dimensions of 300x300 and an <img src="" /> image inside. My goal is for the image to cover the entire container while maintaining its width/height ratio. If the image's width is smaller than its height ...

selecting a radio button and saving its value into a JavaScript variable

How can I assign the return value from a JavaScript script function to a variable inside the HTML body? The function will return the selected variable, but how can I assign it to a variable within my HTML body? <body> <form action="somepage.php ...

What is the best way to show hidden content within a masked div, similar to a tooltip?

In an icon-based menu, a grid consists of several <div> elements. Each element is empty with general CSS styling and inline CSS to set the mask effect. The purpose of using images as masks is to allow the icons to be colored in different ways by cha ...

The functionality of oTable.fnFilter is malfunctioning

I'm trying to implement a search functionality in the thead section of datatables, but unfortunately it's not functioning as expected. $("#listings_row thead input").keyup( function () { oTable.fnFilter( this.value, $(this).attr('id&apo ...

Set the background color of the container row to extend the full width, encompassing

I am working on a grid container and I want to change the background color of the second row within it. Check out my Fiddle This is the HTML markup: <div class="totalContainer totalContainer__space"> <div class="totalContainer__ ...

What is the best way to position a button to the right side of the screen?

Is there a way to align a button to the right of a page? I attempted using text-align: right; and align-content: right; In addition, I want the button to utilize display: flex; #hideShow { display: flex; text-align: right; align-content: right; ...

Using Selenium WebDriver to locate elements by their XPath within a WebElement

I am facing an issue with locating an element in my code using the following snippet: elements = driver.find_elements_by_xpath("//div[@class='Display']") After successfully finding the elements, I want to access the second "Display" element and ...

No input value provided

I can't figure out what's going wrong. In other js files, this code works fine. Here is my HTML code: <table class='table'> <tr> <th>Event</th><td><input class='for ...

Refresh a chart in vue using the chart.js library

Within my Vue application, I have a function that generates a chart. This function looks like this: startChart: function (canvas, type) { // initialize chart.js var ctx = document.getElementById("myChart"); var myDoughnut = new Chart(ctx, { ...

What is the best way to vertically center a caption when an image is being hovered over

I'm facing an issue with aligning my caption vertically inside a div when hovering. The image within the div is larger than the div, and I want the caption to be at the center of the div. HTML <div class="container-fluid"> <div id="pag ...

Issue with Bootbox alert causing focus to not return to the input box

For my latest project, I decided to upgrade from standard alert and confirm boxes to the more stylish bootbox. However, I encountered a problem where the focus does not return to my input field after closing or dismissing the bootbox. bootbox.alert("P ...

What is the best way to trigger the Javascript blur event following a click event that results in the element losing focus

Encountering this issue multiple times has left me dissatisfied with the solutions I've implemented in the past. The challenge lies in dealing with an input box that triggers a validation process on blur, while also having a button that populates the ...

Switch to display only when selected

When I click on the details link, it will show all information. However, what I actually want is for it to toggle only the specific detail that I clicked on. Check out this example fiddle Here is the JavaScript code: $('.listt ul').hide(); $( ...

Execute a function on every item within a loop by utilizing jQuery

My view-model includes a data grid similar to the one displayed below <table> @foreach (var item in Model) //for(int i=0;i<Model.Count();i++) { using (Html.BeginForm("Edi ...

Will upgrading jQuery UI 1.7.2 to 1.8.7 lead to enhanced performance?

My website relies solely on jQuery UI dialogs and buttons. Everything seems to be functioning well overall, but some users have reported occasional performance issues where the system is not as responsive as they would like. I noticed that upgrading from ...

Using JavaScript to generate a <style> element and accessing the cssRules

After spending countless hours trying to solve this problem, I'm hoping that my question isn't too foolish. This is a continuation of a previous question about creating a style tag with JavaScript on Stack Overflow. The solutions provided by Tom ...

What is the complete list of features that ColorTranslator.FromHtml() supports and what are the reasons behind its departure from traditional CSS color interpretation guidelines

I'm looking to enhance an API by providing users with the ability to specify the color of something. I want it to accept various representations of colors, such as hex codes and CSS colors. Initially, I thought that ColorTranslator.FromHtml() would fu ...

What is the proper way to encode image URLs for use in CSS?

For the div element in my code, I want to allow users to input a URL that will be applied as a CSS background image, like this: background-image: url("/* user specified URL here*/") I'm concerned about security. How can I properly escape the URL to ...