How to implement smooth scrolling to a specific div in Bootstrap 4

My experience with Bootstrap 4 has been somewhat puzzling as the scroll to div functionality seems to be working only on mobile phones or smaller screens.

Below is the Javascript code I am using:

 <script>
    $(".navbar-nav li a").click(function(event) {
        if (!$(this).parent().hasClass('dropdown'))
            $(".navbar-collapse").collapse('hide');
    }); </script>

The navbar link in question:

        <li class="nav-item">
            <a class="nav-link" href="#about-us"><button type="button" class="btn btn-green">About</button></a>
        </li>

And here's the specific div element I'm trying to scroll to:

  <div class="about" id="about-us">
    <div class="container">
      test
    </div>
  </div>

Answer №1

The 'navbar-brand' class is causing overlap with the 'navbar-nav'. To fix this, you can add a z-index to the 'navbar-nav' in your HTML page like so:

<ul class="navbar-nav ml-auto" style="z-index:1;">

Answer №2

To customize your css design, you could include the code snippet below in your stylesheet:

.navbar-brand.mx-auto {
  width: 216px;
  right: 0;
  left: 0;
}

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

What is the reason behind the unexpected behavior of shallowReactive?

Recently, I started using vue3 and I am a bit confused about the concept of shallowReactive. I have learned that only root-level properties are reactive for a shallow reactive object. However, I noticed that even when I click the add button, the value of ...

"Learn the steps for accessing the most recent version of a ReactJS application from the server

I have my react app hosted on a Netlify domain. How can I ensure that users who have previously loaded older versions of the app are redirected to the most recent deployed version? ...

"Enhance your Angular application with Datatables using $http to fetch and display data

Currently, I'm working on a project with AngularJS where I'm fetching data from the server using the $http service. Here's a snippet of the code: $http({ method: 'GET', url: $rootScope.apiURL + 'getAllClientLocations/ ...

Unable to prevent key blocking with event listener

<body id="body" runat="server" onkeydown="return showKeyCode(event)"> Whenever a key is pressed, IE8 (or in compatibility mode) triggers an exception pointing to an issue in line x, which is related to the body tag. How can I resolve this? The JavaS ...

React - Incorporating key presses to navigate to different components

Is there a method to navigate to components when a key is pressed? For instance: Press "Tab" to move to the first row of my table; Press "Enter" to go to an input field. I attempted to use React references but have not been successful. ...

Searching for parameters wrongly triggering the id on a different route

Having recently delved into mongoose, I must apologize in advance for any misuse of terminology on my part. Below is the content of my routes file: const express = require('express'); const router = express.Router(); const passport = require(&a ...

Setting the position of a tooltip relative to an element using CSS/JS

I'm struggling to make something work and would appreciate your help. I have a nested list of items that includes simple hrefs as well as links that should trigger a copy-to-clipboard function and display a success message in a span element afterwards ...

Issue with Slick Slider: Next Arrow not visible

I'm attempting to display the next and previous arrows alongside the product slider, similar to the Slick Slider example. However, I'm facing an issue where the expected fonts are not loading properly. Below is my code: HTML <div class="s ...

Generate a hard copy of the data table row without needing to view it beforehand

Here are some records from a table: +--------+---------+-------+----------+--------+ | Name | Address | Phone + Email | Action | +--------+---------+-------+----------+--------+ | Andy | NYC | 555 | <a href="/cdn-cgi/l/email-protection" cl ...

translating xpath code into css styling

Can you help me with converting this xpath to css? By.xpath("//div[@id='j_id0:form:j_id687:j_id693:j_id694:j_id700']/div[2]/table/tbody/tr/td"); I've tried a couple of options, but none of them seem to work: By.cssSelector("div[@id=&apos ...

Bizarre error when injecting Factory into Controller in AngularJS

After scouring through countless posts on various forums, I have yet to find a solution to my unique problem. I find myself in a peculiar situation where I am trying to inject a Factory into a Controller, and despite everything appearing to be in order, i ...

The unit tests are passing successfully

Trying to create unit test cases for a web API call. This one showcases success: Success Unit Test (jsfiddle) getProduct("jsonp","https://maps.googleapis.com/maps/api/e Here is an example of an error, but the test result still shows "pass": Error ...

Strange behavior is observed when using ng-view inside ng-controller, especially when refreshing the

Here is the code I am working with: <body ng-controller="CoreCtrl"> <div ng-cloak> <!-- NavBar --> <div ng-include="'/app/core/navbar.html'"></div> <!-- Main content --> <div class="con ...

There seems to be an issue with the EventList constructor in one part of the code, while it functions correctly in

Having a peculiar issue with my Django (1.8) app that includes a JavaScript feature. Everything works fine in one section, but I encounter an error in another: Uncaught TypeError: EventList is not a constructor The code in the JavaScript file looks like ...

Retrieving the Inner HTML content of a listing upon clicking its button

I need help with my code that involves displaying a list of places and allowing users to add individual places to a separate list. When a button is clicked, it should change the innerHTML of the list item to match the result. However, I'm facing an is ...

Could Bootstrap CSS components be transformed into Tailwind CSS?

Incorporating the Tailwind CSS library into my current web project has been a game-changer. I am now considering the possibility of converting all of the Bootstrap CSS components to use in my project. Is this transition feasible? ...

Tips for identifying and logging out a dormant user from the server side using Angular 2 Meteor

I'm currently diving into Angular 2 Meteor and working on a project that requires logging out the user when they close their browser window. I also need them to be redirected to the login page when they reopen the app. After searching online, I could ...

What could be the reason for the background image not displaying?

Below is the HTML code I have: <div class="content-wrapper"> <div class="center"> <h1>title</h1> </div> <div class="lr"> <p> text </p> </div> </div> The CSS for the content-wrapp ...

Load a section of the webpage without using AJAX technology

I am creating a website and I would like the left menu to remain fixed while loading the content of the clicked option. Currently, each menu link uses AJAX to return the requested content. Although it works well, I would like to find an alternative to avo ...

Using async/await with Middleware in Express

I'm struggling to grasp the concept of writing middleware in Express that uses async/await without leaving a floating Promise after execution. Despite reading numerous blogs and StackOverflow posts, it appears that there is a common pattern for utiliz ...