Issues with Navbar Toggle Button Functionality in Bootstrap Version 4.1.3

I am utilizing BootstrapCDN v4.1.3 and I am aiming to have my navbar fixed at the top of the user's browser consistently. However, when I apply the position: fixed; property to the nav div, the links become unclickable in desktop mode and the mobile toggle button fails to function in mobile mode. Removing the position: fixed; attribute resolves these issues but disrupts the layout by pushing down the stock video element. Can someone assist me in achieving a properly functioning navbar while keeping it fixed at the top?

nav.navbar {
  background-color: rgba(144, 188, 244, .8) !important;
  position: fixed;/* <---- Causing the navbar issue */
  width: 100%;
}

div.stockVideo {
  padding: 0;
}

#stockVideo {
  width: 100%;
  height: auto;
}
<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8>;
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="css/normalize.css">
  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  <link rel="stylesheet" href="css/custom.css">
  <title>Website</title>
</head>

<body>
  <!-- Navbar -->
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">
      <img src="media/placeholderLogo.png" width="44" height="44" alt="Logo">
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</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>
      </ul>
    </div>
  </nav>
  <!-- Stock video -->
  <div class="container-fluid stockVideo">
    <video autoplay muted loop id="stockVideo">
            <source src="media/stockVideo.mp4" type="video/mp4">
        </video>
  </div>
  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>

</html>

Answer №1

Adjusting the navbar z-index: value to 1 resolves this problem:

nav.navbar {
  background-color: rgba(144, 188, 244, .8) !important;
  position: fixed;
  width: 100%;

  z-index: 1;
}

Furthermore, it is recommended to set the padding-top equal to the height of your navbar on the body element like this:

body {
    padding-top: 59px; /* adjust based on navbar height */
}
nav.navbar {
    top: 0; /* reposition the header at the top */
}

Answer №2

Another option to consider is using the bootstrap fixed-top class in order to stabilize the navigation bar:

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">

Answer №3

Ensure there is enough padding at the top of the video to accommodate the Navbar height.

#stockVideo {
  width: 100%;
  height: auto;
  padding-top: 60px;
}

https://www.codeply.com/go/YWnrU7WAXM

In an ideal scenario, it is recommended in the Bootstrap documentation to apply padding-top to the body...

"Fixed navbars use position: fixed, meaning they’re pulled from the normal flow of the DOM and may require custom CSS (e.g., padding-top on the ) to prevent overlap with other elements."

body {
  padding-top: 60px;
}

This query has been addressed previously here.

EDIT

If you desire a fixed Navbar, utilize the Bootstrap fixed-top class. Simply using position:fixed alone will not suffice as z-index needs to be set as well. Demonstrated here, the fixed-top class functions effectively: https://www.codeply.com/go/YWnrU7WAXM

<nav class="navbar navbar-expand-lg navbar-light fixed-top bg-light"></nav>

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 allows me to modify the border color and thickness of my table's <thead>, but prohibits me from changing the background color?

I have successfully changed the border styling of the top bar in the table, however, I am struggling to change the background color no matter what I try. Can someone point out where I might be making a mistake? Here is my code: <table> <thead> ...

Tips for creating a continuous slide and fade effect on table rows

I am working with a table that has 6 rows of data. My goal is to initially show 2 rows of data, then fade out and display the next 2 rows. This process would continue, showing 2 rows at a time every (n) seconds. Below is the code for the table: <table ...

Using JQuery in an ASP.NET web page containing numerous dynamically generated controls

I'm feeling a bit lost. Our asp.net Questionnaire is being dynamically created based on business rules and data from SQL. The questionnaire, represented as a dynamic table, can contain up to 21 questions. Depending on the response (yes, no, in progre ...

Do elements automatically adapt size in different browsers?

I'm currently designing a website at www.50s.co and everything seems to be working fine in Chrome. However, when I check it in Firefox or IE, the background images appear to be sized differently. Even though the image sizes are supposed to be the same ...

Is it possible to create distinct overlapping divs without using absolute positioning?

I'm seeking assistance in developing the view shown below. I am familiar with using position absolute, but I'm wondering if there is a way to achieve this without relying on absolute values. https://i.sstatic.net/m13cl.png ...

Using CSS to Create a Background with RGBA Color and Image

Having an issue with my CSS. I'm trying to create a scrolling background for the left section of my website. The RGBA is currently overlapping the entire page, but I only want it to overlap the background image. The same goes for the gridtile (the ov ...

jQuery function to alternate between appearing and disappearing captions every 5 seconds

I have a unique project that requires my image captions to both appear and disappear every X seconds. While I have successfully achieved this effect once, I need the captions to continuously "loop". Here is the code I am currently using: <figure> ...

What could be the problem with Codeigniter's login session when using ajax with jQuery?

I am new to Codeigniter and have created a Login system with jQuery in Codeigniter. However, I am facing a session problem. After submitting the login form, the session is created perfectly. But upon redirecting to the next page after login, the session ge ...

Using Discord JS to remove a replied message

I'm attempting to remove a specific message with a specific event using the following code: await interaction.reply({ content: `content` }) .then(message => { console.log(message); client.on('message ...

Apply the active class to a section in the menu

I am exploring how to dynamically add the "active" class to a specific section of my menu based on which link within that section has been clicked. After successfully implementing the active class functionality for individual links using jQuery, I am confi ...

Infinite redirection occurs after loading with Jquery if Scriptaculous is installed

Whenever I use jQuery load to load a page that contains scriptaculous, the page keeps redirecting me back to itself after the initial load. Below is the jQuery code I am using to load pages: jQuery( document ).ready(function( $ ) { // Code that uses jQue ...

Determining the Ideal Size for Expandable Text Headers

I need help adjusting the spacing between headers on my expandable sections, similar to what is shown here. I have managed to change the font size but as I increase it, the headers start to overlap. I am quite new to this so forgive me if this is a simple ...

What is the best way to repeatedly execute my function at intervals using setInterval?

After attempting to run a for loop 10 times with setInterval to call my function again, I realized that my for loop only runs ten times. How can I fix this issue? function randomThumbNews() { for(var i=0;i<10;i++){ $.ajax({ ...

Creating a collapsible navbar using JavaScript

I have implemented a responsive navbar that shrinks with the page size using @media screen. Everything works well, but I need the navbar to collapse into a vertical drop-down menu when the page size is very small, requiring a click to open. Unfortunately, ...

Retrieve the current time in 24-hour format and store it in a variable using AngularJS with Javascript

I need to create a time slot using Javascript without jQuery. The goal is to generate a list of intervals between the first and last time provided, with the slots transitioning from am to pm after reaching 12 numbers. For example, if the start time is 11 a ...

What is the best way to initiate an animation once the one before it has finished?

I am facing an issue with my animation function where all animations play simultaneously. This is not the desired behavior; I would like to play each animation after the previous one ends. Can someone guide me on how to achieve this? canvas = document.get ...

What is the best course of action when dealing with a delayed response?

In this scenario, we have two buttons that each call a method which processes image data: var NUMBER_OF_IMAGE_REQUEST_RETRIES = 3; var IMAGE_REQUEST_TIMEOUT = 3000; processImage: function(image_data) { var main_response = $q.defer(); var hash = ...

Creating a dynamic Bootstrap 4 modal link directly within the Datatables.js plugin

I am currently utilizing the Datatables.js jQuery plugin to construct HTML tables (jQuery version 3.2.1). The HTML table generated by Datatables needs to include a clickable link in one of the column cells (author_id) that opens a Bootstrap 4 modal and sen ...

I am attempting to design a working Hamburger icon using HTML and CSS, but it is not collapsing as intended

I am new to Bootstrap and experimenting with it. The responsive navbar in Bootstrap is not functioning as expected on my screen. Can someone help me identify the issue and fix it? <!DOCTYPE html> <html> <head> <link rel=&q ...

What steps can be taken to adjust a module required in Node.js prior to initiating the build process?

Module A.js (standard NPM package): module.exports = { ... const wsUrl = `ws://${customHostname}:${customPort}/sockjs-node/websocket`; ... }; Module B.js: const a = require('A'); Is there a way to substitute ${customHostname} & ${cu ...