Issue with bootstrap Navbar in the latest version 4.0.0-alpha.2 causing functionality errors

The bootstrap Navbar is experiencing issues with Bootstrap 4.0.0-alpha.2 as well as scroll spy. I attempted to switch both the script and CSS files with Bootstrap 3.3.7 which worked fine. However, with this version, both the styling of the navbar and the spy scrolling are not functioning properly.

<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <meta http-equiv="x-ua-compatible" content="ie=edge"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">

    <style type="text/css">

      body{

        position:relative;

      }

      #home{

        margin-top:50px;

      }

      #home {padding-top:50px;height:500px;color: #fff; background-color: green;}
      #one {padding-top:50px;height:500px;color: #fff; background-color: #1E88E5;}
      #two {padding-top:50px;height:500px;color: #fff; background-color: #673ab7;}
      #three {padding-top:50px;height:500px;color: #fff; background-color: #ff9800;}
      #two1 {padding-top:50px;height:500px;color: #fff; background-color: #00bcd4;}
      #two2 {padding-top:50px;height:500px;color: #fff; background-color: #009688;}

    </style>



  </head>
  <body data-scroll="spy" data-target="#myNavbar" data-offset="10">

    <nav  class="navbar navbar-inverse navbar-fixed-top" id="myNavbar">

      <div class="container-fluid">

        <div class="navbar-header">

          <button type="button" class="navbar-toggle"data-toggle="collapse" data-target="#myNavbar">

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

          </button>


          <a href="#" class="navbar-brand">WebSiteName</a>

        </div>

        <div class="collapse navbar-collapse" id="myNavbar">

          <ul class=" nav navbar-nav" >

            <li class="active"><a href="#home">Home</a></li>

            <li><a href="#one">Section 1</a></li>

            <li class="dropdown"><a  class="dropdown-toggle" data-toggle="dropdown" href="#">Section 2<span class="caret"></span></a>

              <ul class="dropdown-menu" >

                <li><a href="two1">Section 2-1</a></li>

                <li><a href="two2">Section 2-2</a></li>

                <li><a href="two3">Section 2-3</a></li>

              </ul>

            </li>

            <li><a href="#three">Section 3</a></li>

          </ul>
        </div>
      </div>

    </nav>


    <div id="home" class="container-fluid">

      <h1>Home</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>


    <div id="one" class="container-fluid">

      <h1>One</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>                                                             



    <div id="two" class="container-fluid">

      <h1>two</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>



    <div id="three" class="container-fluid">

      <h1>Three</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.4/js/tether.min.js" ></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>

    <script type="text/javascript">

      $("body").scrollspy({target:"#myNavbar"});

    </script>

  </body>
</html>

Answer №1

Don't forget to update your HTML to match the new Bootstrap 4 navbar design.

If you need help, check out this link for a live example: http://codeply.com/go/yPEQsECngS

I tested your code with a Bootstrap 4 upgrade tool and it looks like everything is working with scrollspy. Just remember that Bootstrap 4 is still in ALPHA stage, so there may be changes coming up.

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

Python raises a KeyError if JQuery is included

I have encountered an issue with the code snippet below, where I am attempting to define a variable within the HTML. Oddly enough, when I exclude the JQuery script, everything functions as expected. However, upon reintroducing the JQuery script, the functi ...

Guide to storing a variable value when a user clicks on the client-side in a Grid View:

How can I store data in a variable on client click within a grid view? I have a Stored Procedure that returns Service Id based on the Department code provided. We are binding these details to a Grid View. How can we bind the Service Id to a variable that ...

Combining multiple materials in Three.js using onBeforeCompile

Imagine having a scenario like this: //some chunks i want to override for functionality FOO const myNormalChunks = { beginnormal_vertex, defaultnormal_vertex, normalmap_pars_fragment, } //a version of `MeshStandardMaterial` that does FOO instea ...

observable arrays in knockoutjs

To simplify the problem I'm facing, let's consider this example: var ViewModel = function() { this.self = this; self.test = ko.observableArray([]); self.test2 = ko.observableArray([]); self.test2.push('1'); self.test.push({ 'f ...

Error TS7053 indicates that an element is implicitly assigned the 'any' type when trying to use a 'string' type to index a 'User_Economy' type

Struggling with a particular question, but can't seem to find a solution. Error: TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'User_Economy'. No ind ...

Print media not affected by Bootstrap styling

Below is the code I am using to display a table within my application: var elementToPrint = this.mainTable.get(0); newWin = window.open(""); newWin.document.write('<html><head><title>' + elementToP ...

Creating uniform heights for HTML column-based tables using divs in a React environment

I am developing a unique column-oriented and div-based table using React with Typescript. The data outside the table is organized in a column-based structure, rendering column 1 followed by row 1, row 2, row 3, then column 2 with its respective rows. The ...

Verifying child attributes within a collection using AngularJS expressions

Is there a way to write an angular expression that can check each child item in a list and return true if any child has a specific property value? My issue involves a chart legend generated by an ng-repeat expression. I want the wrapping element to be sho ...

Having trouble with the dropdown multiselect feature in AngularJS?

I'm striving to develop a straightforward multi-select dropdown utilizing angular JS, bootstrap, and JS. This dropdown should display days (mon, tue...sun), with options for select all and unselect all. My goal is to create a controller that will de- ...

Database does not retain the updated image during the process

I am currently using Formidable along with the fa-extra module of Node.js to store files in MongoDB. It is functioning properly when I insert data, but I'm encountering difficulties when trying to update using Formidable. form.on('file', fu ...

Challenges arise when attempting to authenticate a user with password.js

Currently, I am working on implementing validation using passport.js and ES6. Below is the validation function that I have created: passport.use(new BasicStrategy( function(login, password, callback) { User.findOne({ login: login }).select(&a ...

Limit on the number of users for organizations

Creating a website that connects users to organizations, where users can request to join an organization that has a 500 people limit. However, the function is not working correctly as it fails to check if the current number of users (current_users) is less ...

Obtaining the value of cookies in express js is a simple task that

Is there a way to retrieve the value of a cookie? const cookieParser = require('cookie-parser'); app.use(cookieParser()); app.get('/', (req, res) => { res.setHeader('Set-Cookie', 'Cookie=HELLO'); }); I' ...

Ensuring Vue dropdown retains focus with custom configuration

After an unsuccessful search for a solution, I decided to write a question myself. My goal is to create a basic drop-down menu component in Vue with a toggle button that collapses the menu when focus leaves the component. Despite using @blur and @focus ev ...

Tips for accessing and manipulating the value within a textbox with additional features

I am currently in the process of developing a website with numerous static HTML pages (e.g. 1.html, 2.html, 3.html, and so forth). Each page includes a textbox where users can input a specific page number to be redirected to. For example, if a user enters ...

Obtain a range of dates within a specified timeframe by utilizing JavaScript

Is there a way in JavaScript to retrieve a list of days between two dates in MySQL format without using any libraries? Here is an example of how it can be done: function generateDateList(from, to) { var getDate = function(date) { //MySQL Format ...

Impact of Jquery on dropdown menus in forms

Currently, I have a script for validating form information that adds a CSS class of .error (which includes a red border) and applies a shake effect when the input value is less than 1 character. Now, I also need to implement this validation on various sel ...

Undefined index when decoding JSON data

When calling the save function, a $.post is sent to 'upp.php' as follows: function save(){ var oldItems = JSON.parse(localStorage.getItem('itemsArray')) || []; var newItem = {}; var num = document.getElementById("num").value; newIte ...

Troubleshooting a Navigation Tab Problem in Bootstrap 4

Hi, I am new to using bootstrap. Can anyone help me figure out how to achieve the look in the image using bootstrap-04? I want this design to be consistent across all devices, but I am having trouble implementing it. Any guidance is appreciated. Thank you ...

Passport.js `isAuthenticated()` function displaying erratic behavior: returning false instead of true in some cases

Utilizing Passport for enabling user logins via Google with session storage in Postgres. Everything seems configured correctly, but isAuthenticated() is returning inconsistent values. The inconsistency arises in the success callback after authentication. ...