New feature in Bootstrap 5: Fixed navigation with smooth scroll effect

Recently, I made the switch from Bootstrap 4 to Bootstrap 5 for my template. Surprisingly, I didn't encounter this issue with Bootstrap 4. Initially, I suspected that adding a flex container inside the navbar might be causing the problem, but that doesn't seem to be the case. The fixed navbar on mobile devices scrolls down slightly, even though it has position:fixed. How is this even possible?

You can see the live version here


      <nav
        class="navbar navbar-expand-lg navbar-light fixed-top"
        style="background-color: #ffffff"
      >
        <div class="container-fluid">
          <a class="navbar-brand" href="#">
            <img
              id="logosvg"
              src="assets/img/mine.svg"
              height="40px"
              alt="Myne social logo"
              style="margin-top: 0.5em; margin-left: 0.5em"
          /></a>
          <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#navbarNav"
            aria-controls="navbarNav"
            aria-expanded="false"
            aria-label="Toggle navigation"
          >
            <span class="navbar-toggler-icon"
              ></span>
          </button>
          <div
            class="collapse navbar-collapse justify-content-end"
            id="navbarNav"
          >
            <ul class="navbar-nav">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#aboutus"
                  >About us</a
                >
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#mynepulse">Myne Pulse</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#instantgratification"
                  >Instant Gratification</a
                >
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#partners">Our Partners</a>
              </li>
              <li class="nav-item desktop">
                <a
                  href=""
                  target="_blank"
                  ><button type="button" class="blue">Get Started</button></a
                >
              </li>
            </ul>
          </div>
        </div>
      </nav>

Update: As shown in the screenshot, when viewing on mobile and scrolling down, the top bar moves slightly up and then returns to its position when scrolled up.

https://i.sstatic.net/qwIuV.jpg

Answer №1

To achieve the desired outcome, simply incorporate the following CSS snippet into your code:

@media only screen and (min-width: 1000px) {
    .fixed-top {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        z-index: 1030;
        height: 80px;
    }
}

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

Add a border to the progress bar that has no content

I have configured a Bootstrap Progress Bar with the following code snippet: <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax=& ...

Ways to conceal a child div element without using any specific ID reference

I encountered an issue where I need to conceal all divs within a parent div except the first one. The challenge is that these divs do not possess any unique identifiers. Is there a way to achieve this task using CSS or pure JavaScript? <div role="list ...

What is the optimal location for storing numerous blocks of text (without utilizing a database)?

If I have a control used on 10 different pages with a help icon, each page needs to display its own unique paragraph of help text. The selection of which help text to show is determined by a JavaScript function. In my scenario, having 10 paragraphs will n ...

Challenges encountered when redirecting users with a combination of javascript and php

I have a login form that triggers a JavaScript function upon submission. This function calls a PHP page to process the input. The issue I'm facing is with how the redirections are displayed based on the user's role type. It attempts to display t ...

When attempting to showcase an image within an Angular form, the error message "Form control with unspecified name attribute lacks a value accessor" is displayed

I have a scenario where I am overlaying icons on an image within my ngForm. The goal is to allow users to drag the icons and save their new location when the form is submitted. Everything works as expected, but I encounter a pesky error whenever the page l ...

How to retrieve the index upon clicking in Javascript

In my 3d art gallery project, I am utilizing plain JavaScript. The task at hand involves populating certain columns with images by pulling from an array of image sources. On click, I need to retrieve the index of the clicked image so that I can extract add ...

The webpage freezes when attempting to run jQuery with Selenium

I'm currently facing an issue where my selenium script hangs the webpage whenever I try to find an element using jQuery. The script doesn't execute and a pop up appears in the browser with the message "A script on this page may be busy, or it may ...

Position a single div on the left-hand side and arrange two divs on the right using display:flex

Is there a way to achieve this layout without adding another div, using only parents and 3 child elements? I had tried using height: max-content, but it didn't work as expected. .container { display: flex; flex-wrap: wrap; } .item { flex-bas ...

Menu with sticky scroll disappears when the position is offset by 500 pixels from the bottom

I am working on a sticky menu feature that appears when the user scrolls down 500px from the top of the view. I would like it to also hide when the user reaches 500px from the bottom of the page. Any suggestions or tips are greatly appreciated. var stick ...

changing pictures with jquery

Struggling with this code snippet: $('#clicked_package').css({"background-image" : "url(img/head_2.png)"}).fadeOut("slow"); $('#clicked_package').css({"background-image" : "url(img/head_2_normal.png)"}).fadeIn("slow"); No matter which ...

Tips for entering Tamil characters in text boxes on a form field

Within my form, I have a set of text boxes. I am looking to input text in Tamil font for specific text boxes - around 5 out of the total 10 text boxes in the form. If you know how to enable Tamil font input for multiple text boxes (rather than just one as ...

How can I create a CSS Layout Template Module with a fixed footer?

Currently exploring the capabilities of the JQuery library for CSS Layout Template module Wondering if it's possible to set the height of a placeholder using *, allowing it to either push content down or fill up remaining space based on the viewport ...

Ways to address time discrepancies when the countdown skips ahead with each button click (or initiate a countdown reset upon each click)

Every time I click my countdown button, the timer runs normally once. But if I keep clicking it multiple times, it starts skipping time. Here are my codes: <input type="submit" value="Countdown" id="countdown" onclick="countdown_init()" /> <div i ...

The justify-content-center property in Bootstrap is failing to properly align content in a row to the center

I recently created a section using Bootstrap that contains 8 buttons, with 5 in the first row and 3 in the second. However, the alignment of the content is not as I envisioned. See the current layout below: Click here for image Here's how I want to ...

The functionality of the Bootstrap4 accordion is not functioning according to my expectations

My goal is to create a unique e-commerce checkout page design. Each panel would be opened sequentially, with the next panel unfreezing when the action button of the current panel is clicked. However, I seem to be making a mistake as it is not working as in ...

Observing changes in the dimensions of flex children using MutationObserver

Considering the following structure of the Document Object Model... <div id="outer-container"> <div class="side-panel"><div width="200px"/></div> <div id="content"><!-- some content --></div> <div class=" ...

Concealing text in multi-select option of Bootstrap when overflowing horizontally

I am attempting to create a multi-select feature with only one horizontal scroll bar using bootstrap. However, I do not want each option to have its own horizontal scrollbar. When I choose the longest option (123456789012345678901234567890), only part of ...

The border feature functions correctly in Google Chrome, however, it does not work in Internet Explorer

I recently created a GridView using asp.net with a black border color. However, I encountered an issue where certain lines were showing up in white which I didn't want to see. It seems there may be a problem when working with child elements, particula ...

Displaying a collapsible table directly centered within the table header

I am having trouble centering my table header in the web browser page. When I click the "+" button, the data is displayed beneath the table header, but I want the collapsible table to be centered directly below the header. I have tried making changes in CS ...

The CSS styles are not recognized by the Windows 2003 server

After deploying my webapp, which was created using asp.net, to a testing server (Windows 2003 SP2, IIS6), I encountered an issue. When I accessed the default page, none of the CSS styles were applied. Only plain text or formatting from the .aspx file was v ...