What steps can be taken to prevent the bootstrap hamburger icon and collapsible menu from having a noticeable jump when activated?

I'm facing an issue with my hamburger menu where it jumps below the icon when clicked. I've tried adjusting heights and removing fixed values but it didn't help. I want the collapsed menu to smoothly appear below the icon without any jumping. Here is the code snippet:

    *, ::before, ::after {
  box-sizing: border-box;
}

:root {
  --blue: #3a2eb6;
  --white: #fff;
  --red: #cd3f33;
}
html{
  font-size: 1em;
}
nav{
  background: var(--white);
}
nav .logo{
  background: url("../images/logo-mobile.jpg") no-repeat 0 0/contain transparent;
  display: block;
  overflow: hidden;
  width: 13.6875rem;
  height: 2.875rem;

}

nav ul li a{
  color: var(--blue);
}

nav ul li{
  margin: 0 0.25rem;
}

nav div.sign-in{
  display: none;
  margin: 0 0.25rem;
}








button.navbar-toggler span i.menu-toggler{
  color: var(--red);

}





@media screen and (min-width: 768px)
{
  nav .logo{
    width: 17.125rem;
    height: 3.5625rem;
  }
  nav ul li.sign-in-mobile a{
    display: none;
  }

  nav div.sign-in{
    background-color: var(--blue);
    padding: 0 1.5rem;
    display: block;
    margin-left: 15rem;
  }

  nav div.sign-in a{
    color: var(--white);
  }

  #bootstrap-override .navbar-nav{
    flex-direction: row;
    justify-content: flex-end;
    border-bottom: .1rem solid var(--red);
  }
}

@media screen and (min-width: 992px)
{
  #bootstrap-override .navbar-expand-lg .navbar-toggler{
        display: none;
      }

      nav .logo{
        width: 24.625rem;
        height: 5.25rem;
      }
      #bootstrap-override .navbar-nav{
        border: none;
        margin-left: 2rem;
      }

      nav div.sign-in{
        order: 1;
        margin: 0 0.25rem;
        white-space: nowrap;
      }
}
*/
  

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="description: goes here" name="description">
    <meta content="HTML, CSS, XML, JavaScript" name="keywords">
    <meta content="Twisted Yogurt" name="author">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>Home</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body id="bootstrap-override">
    <header>
        <nav class="navbar navbar-expand-lg">
            <div class="container justify-content-space-between">
                <a class="navbar-brand" href="index.html">
                <div class="logo"></div></a>
                <div class="sign-in">
                    <a class="nav-link" href="#">Sign In</a>
                </div><button aria-controls="myTogglerNav" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler d-lg-none" data-target="#myTogglerNav" data-toggle="collapse" type="button"><span><i class="fa fa-bars menu-toggler"></i></span></button>
                <div class="collapse navbar-collapse" id="myTogglerNav">
                    <ul class="nav navbar-nav">
                        <li class="nav-item active">
                            <a class="nav-link" href="index.html">Home</a>
                        </li>
                        <li class="nav-item dropdown">
                            <a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Menu</a>
                            <ul aria-labelledby="nav-link" class="dropdown-menu">
                                <li>
                                    <a href="#">Froyo</a>
                                </li>
                                <li>
                                    <a href="#">Smoothies</a>
                                </li>
                                <li>
                                    <a href="#">Boba</a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Build</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Community Recipes</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">About</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Contact</a>
                        </li>
                        <li class="nav-item sign-in-mobile">
                            <a class="nav-link" href="#">Sign In</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js">
    </script> 
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50323f3f24232422312010647e657e63">[email protected]</a>/dist/js/bootstrap.bundle.min.js">
    </script>
</body>
</html>

Answer №1

Your HTML code has a few errors, such as placing <div> directly inside of <ul>. It's important to ensure your code is valid and properly indented for readability and structure.

Refer to the documentation at: https://getbootstrap.com/docs/4.5/components/navbar/ You need to position div#myTogglerNav outside or around ul.nav.navbar-nav, and then move button.navbar-toggler above it.

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

Deactivating controls while displaying the loading bar in AngularJS

I'm currently working on a web application using AngularJS. I want to incorporate a loading bar to signify long data load times from the server. To replicate heavy data loads, I am utilizing $timeout to trigger the loadbar when the operation begins a ...

What is the procedure for incorporating JavaScript into my tic-tac-toe game's HTML and CSS?

I have created a simple Tic Tac Toe game using HTML and CSS. Although there is no embedded Javascript, I do reference a Javascript file for functionality. Can anyone provide me with the most straightforward Javascript code that will display an 'X&apos ...

Is it possible to retrieve stored colors from the Back End and incorporate them into an SCSS file?

Currently, I am in the process of restructuring my code to make it more clear and easier to maintain. I have a concept in mind, but I am struggling with how to implement it effectively. To enhance cleanliness and efficiency, I plan to create a separate _co ...

How to target only the parent div that was clicked using jQuery, excluding any

I have attempted to solve this issue multiple times, trying everything I could find on Google and stack overflow without success. At times I am getting the span element and other times the div - what could be causing this inconsistency? $(".bind-key"). ...

Toggle the radio button selection

$("input[type='radio']").each(function() { if ($(this).is(":checked")) { $(this).css('background', 'blue'); } }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> &l ...

Step-by-step guide on designing a search bar integrated with an image submit button

I have a task to replicate the search bar design of Google Images. This is the current state of my html code: <form id="search"; action="https://www.google.com/images"> <input type="text" name="q ...

"Implement a feature that allows for infinite scrolling triggered by the height of

Looking for a unique solution to implement a load more or infinite scroll button that adjusts based on the height of a div. Imagine having a div with a height of 500px and content inside totaling 1000px. How can we display only the initial 500px of the div ...

Notifying individuals of a file's unavailability using HTML tags

I recently created an API that is designed to deliver files to the frontend. Here is how it looks: <a href="downloadFile.aspx?file=token" download target="_blank"> The file download functionality is working fine. However, the issue arises when the ...

Setting the border-radius property for the bar chart in ChartJS

Currently, I am in the process of developing a stacked bar chart using ng2-chart, an Angular-2 version of ChartJs. In my attempt to create a bar chart with rounded corners as shown in the attached image, I have been facing difficulties finding the necessa ...

What is the best way to ensure that the content on my webpage stays below the navbar, no matter the height of the

I've been working on my homepage layout and encountered an issue with positioning the content below the navbar, which is centered on the page. Every time I adjust the window height, the content shifts. How can I ensure that it stays fixed below the na ...

Adjust the page height when switching between two divs

Currently, I have two divs that are being displayed one at a time using the toggle method. Please refer to the screenshot below: In the image provided, when the user clicks on "show more", the div will toggle based on the first item in the list. If the u ...

Elements with a lower z-index do not have text drawn over them

I am currently facing an issue with a hidden list on a page that is crucial for my menu. Despite setting the z-index of different elements, the text inside a specific div only displays to one side which is causing alignment issues. Using display:none is no ...

Looping through iterations to create circular patterns

How can I fix my code to draw multiple circles in a loop instead of just one? var ss_links_canvas = document.getElementById("ss_links_canvas"); ss_links_canvas.width = images.length * 41; ss_links_canvas.height = 25; var ss_links = ss_links_canvas.getCont ...

What is the method to fetch CSS properties in relative units like percentages and ems using the .css() function with the selector "$("selector")"?

Using jQuery to retrieve HTML element's css properties hasn't been as effective as desired. To test this issue, the following experiment was conducted: var div = document.createElement("DIV"); div.id = "testdiv"; var testZero = $(div).css("w ...

Unable to load CSS background image

As I develop a website for a fictional company to enhance my skills in HTML, CSS, and JavaScript, I am encountering an issue with loading my background image. If someone could review my code to identify the problem, I would greatly appreciate it. Check ou ...

Conceal a div containing a specific class during the page's loading process, then reveal it once the

Is there a way to hide a specific div class while a page is loading? Here is the structure I am working with: <div id ="container"> <div class="project-item tv"></div> <div class="project-item radio"></div> <div class="pro ...

Navigation bar theme toggle malfunctioning as anticipated

I'm experiencing an issue with the navbar theme change functionality. Whenever I click on the dark mode button, the theme changes for a brief moment and then reverts back to light mode. <!doctype html> <html lang="en"> <hea ...

Can a 3.js element be programmed to interact with a DOM element?

Currently delving into the world of 3D.js, I am curious about the possibility of clicking on a 3D object within a canvas and triggering a JavaScript function. Specifically, I envision being able to click on a cube, which would then present detailed infor ...

Struggling to properly center the footer on my Django template

I'm currently facing an issue when attempting to align my footer in the center of my Django template. The specific class for the footer is Pagination. Base HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict ...

Utilize jQuery to dynamically add a CSS class to a button

When using jQuery to create dynamic buttons, is there a way to add a CSS class to the button during creation without needing an extra line of JavaScript to add the class afterwards? Below is a example code snippet: $.each(data, function (index, value) { ...