Menu in Bootstrap 5 experiencing a jittery effect when hovered over

I am facing an issue with shaking when hovering over the link.nav where I have added a border-bottom to display on hover.

<section id="main_header">
<div class="container-fluid mainbar-bg py-1">
    <div class="container">
       
    <nav class="navbar navbar-expand-lg navbar-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar w/ text</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse"data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav ml-auto mb-2 mb-lg-0">
        <li class="nav-item mx-4 py-4">
          <a class="nav-link active" aria-current="page" href="#">Home<br>
              <span class="nav-link-down">Main Page</span>
            </a>
        </li>
        <li class="nav-item mx-4 py-4">
          <a class="nav-link" href="#">Profile<br>
              <span class="nav-link-down">Management</span>
            </a>
        </li>
        <li class="nav-item mx-4 py-4">
          <a class="nav-link" href="#">Pricing</a>
        </li>
      </ul>

    </div>
  </div>
</nav>


    </div>
</div>
</section>

CSS style:

.nav-link-down {
    font-size: 0.75rem;
    color: #b1b1b1;
}

.nav-link.active {
    color: #1f1e2e!important;
}

.nav-link {
    color: #1f1e2e!important;
}

.nav-link:hover {
    border-bottom: 1px red solid;
}

(Changed the background to dark to highlight a shaking container)

Issue gif

Answer №1

Start by adding the nav-link onto a border and setting its color to be see-through.

enter code here
.nav-link {
color: #1f1e2e!important;
border-bottom: 1px solid transparent;

}

next

enter code here.nav-link:hover {
border-bottom: 1px solid red;

}

Answer №2

To easily prevent a shaking effect, you can simply add this line of code:

border-bottom: 1px #212529 solid;
to the .nav-link class. This will add a 1px border-bottom before hovering, which will be hidden due to the same background-color, resulting in a seamless visual effect.

Check out the demo below. (For best view, run it in full page mode)

.nav-link-down {
    font-size: 0.75rem;
    color: #b1b1b1;
}

.nav-link.active {
    color: #ffffff!important;
}

.nav-link {
    color: #ffffff!important;
    border-bottom: 1px #212529 solid;
}

.nav-link:hover {
    border-bottom: 1px red solid;
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aecccaede8c3d2e9d1ddded0c6d57dc3dedd">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681aefedeadbeb9fe8fafcfbf9ece5c8edbfb8">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<section id="main_header">
<div class="container-fluid bg-dark py-1">
    <div class="container">
       
    <nav class="navbar navbar-expand-lg navbar-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar w/ text</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <!--<span class="navbar-text">
        Navbar text with an inline element
      </span>-->
      <ul class="navbar-nav ml-auto mb-2 mb-lg-0">
        <li class="nav-item mx-4 py-4">
          <a class="nav-link active" aria-current="page" href="#">Home<br>
              <span class="nav-link-down">Home Page</span>
            </a>
        </li>
        <li class="nav-item mx-4 py-4">
          <a class="nav-link" href="#">Profile<br>
              <span class="nav-link-down">Management</span>
            </a>
        </li>
        <li class="nav-item mx-4 py-4">
          <a class="nav-link" href="#">Pricing</a>
        </li>
      </ul>

    </div>
  </div>
</nav>


    </div>
</div>
</section>

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

Entering a value into an HTML textbox using Awesomium in VB.NET

This code snippet is used to split text from a listbox: For Each Item As Object In ListBox1.SelectedItems TextBox2.AppendText(Item.ToString + Environment.NewLine) Next Dim str As String = TextBox2.Text D ...

React-tooltip and a challenge with Server-Side Rendering in Next.js

In my Next.js app, I make use of the react-tooltip library for tooltips. One peculiar issue that I have noticed is that whenever I refresh a page containing a tooltip, I encounter the following error: react-dom.development.js:88 Warning: Prop `dangerously ...

Is there a way to keep my footer fixed to the bottom of the page in Google Chrome?

I recently made some updates to my aging website by adding a footer menu. However, I encountered an issue with the placement of the footer on Google Chrome. It appears too high, overlapping certain elements of the site. I attempted to resolve this problem ...

No overflow is occurring within the DIV element

This code snippet is fully functional on all browsers except for IE. Unfortunately, the overflow feature does not seem to be working correctly. Any assistance would be greatly appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ...

What causes two identical pages to display fonts in different ways?

Two identical pages, hosted on the same server with the exact same Apache configuration and home directory. Each page contains only one sentence of text, unstyled. The strange thing is, when viewed in Chrome and Safari, the fonts render differently, while ...

Retrieve the information in a div element from an external website by utilizing AJAX

Exploring the world of AJAX is new to me, and I am eager to fetch content from a div on an external site and display it on my own website. Below is the current code snippet I have: <html> <head> <script src="https://ajax.googleapis.com ...

Editing input within a Bootstrap 4 popover causes it to lose focus

I am using Bootstrap 4 along with the Bootstrap colorpicker to implement a colorpicker within a popup that includes an input field for setting the color code. However, I am facing an issue where the input field (#color-value) seems uneditable when the popo ...

``Protect your PDF Document by Embedding it with the Option to Disable Printing, Saving, and

Currently, I am facing a challenge to enable users to view a PDF on a webpage without allowing them to download or print the document. Despite attempting different solutions like Iframe, embed, PDF security settings, and Adobe JavaScript, I have not been s ...

Validating radio buttons in Ionic framework

I am currently working on implementing a form in my application using Ionic and AngularJS. I have added validation to all the fields, but I am facing an issue with the radio button validation. The error message is being displayed correctly when no radio bu ...

Looping through elements with jQuery's `each` method within another `

When using div containers in my code, I wanted to loop over them and then iterate through the items within each container. Instead of $('.stackContainer .stackItem').each(, I was looking for a solution like this: // setup stacks $('.stackC ...

Footer mysteriously collapses despite being set to a fixed size + odd performance

I've been working on a web page that features a fixed Navigation bar and Footer for logging information. Both the content and the footer are designed to scroll if needed. Thanks to some experimentation and the valuable input from those who responded t ...

Tips for personalizing the Material-UI sticky header to work with horizontal scrolling

Check out this example of a Material UI table with a sticky header on CodeSandox: https://codesandbox.io/s/yi98d?file=/demo.tsx I encountered an issue where the left side header cells slide behind each other when I added a stickyHeader prop to the Materia ...

Exploring CSS Outlining in Visual Studio 2013

Back in the days of Visual Studio 2010, whenever you opened a CSS file, a window would automatically pop up displaying all the classes and IDs for easy navigation within the file. However, in Visual Studio 2013, I seem to be unable to locate this helpful ...

CSS gallery slideshow with images that smoothly fade-in and fade-out at a specified location

In the image below, at position 4 (marked by yellow circle) from the left where picture 6 is displayed, I want a cross-fade (fade-in/fade-out) gallery of images to take place. Specifically at position 4, I am looking for a cross-fade (fade-in/fade-out) ef ...

Tips for adjusting the size of an image in both the vertical and horizontal axes using CSS

As a beginner in HTML, I am currently facing an issue while trying to display a set of pictures. My goal is to resize the pictures based on the current window size while maintaining the aspect ratio. Despite experimenting with various methods like using wi ...

Fixing the issue of "additional space" in the Login Card with Bootstrap 5

I am currently working on a basic login form using bootstrap and encountering an issue, below is the code snippet: <div class="container"> <div class="row justify-content-center no-gutters" style="padding-top:150px ...

"Unlocking the Power of CSS: How to Effortlessly Align Text and Images

Dealing with an unchangeable piece of HTML can be frustrating, especially when it comes to styling. In my case, I have the following structure: <a title="some title" href="..."> <img src="....jpg"></img> Some text </a> Here ...

Switch up the stylesheet in WordPress when an administrator is signed in

Looking for a way to incorporate conditional PHP code into my theme that will load a different stylesheet when either an admin or a specific user (ID=1) is logged in. Does WordPress have a function that can make this happen? There's a particular div ...

I need some assistance, please. Can someone explain why the Bootstrap card is staying aligned to the left in mobile view

I've tried everything, but it's still not working. Can anyone help me out? Here are some photos. BEFORE AFTER When I view the card on mobile, I want it to stay centered. Could there be some missing code that I'm overlooking? I would great ...

Designed radio buttons failing to activate when focused using a keyboard

I'm facing an issue with radio input buttons that I've dynamically added to a div using jQuery. They function properly when clicked with a mouse, but do not get activated when using the keyboard tab-focus state. NOTE: To style the radio buttons ...