Ways to create a collapsing navigation with a fixed top navbar and scrolling functionality

How can I create a collapsing navigation bar that scrolls with the page using navbar-fixed-top in Bootstrap 4?

<!DOCTYPE html>
<html lang="en>">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.3/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<nav class="navbar navbar-fixed-top navbar-light bg-faded">
<div class="container">
<a class="navbar-brand" href="#">Fixed top</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar" aria-controls="exCollapsingNavbar" aria-expanded="false" aria-label="Toggle navigation">☰</button>
<div class="collapse" id="exCollapsingNavbar">
<div class="p-a-1">
<ul class="nav navbar-nav nav-pills nav-stacked">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<!-- More list items -->
</ul>
</div>
</div>
</div>
</nav>
</div>
</body>
</html>

Answer №1

To achieve a vertical stacking navigation bar like the one in version 3.x, you can add the following CSS code to your project:

.navbar .navbar-nav>.nav-item {
    float: none;
    margin-left: .1rem;
}
.navbar .navbar-nav {
    float:none !important;
    max-height: 240px;
    overflow: auto;
}
.navbar .collapse.in, .navbar .collapsing  {
    clear:both;
}

Check out the demo here:

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

Error: The value of data.isbn is not defined

After encountering the error message below: TypeError: data.isbn is undefined I modified the code to include the data.isbn == null condition as shown below: $.ajax({ type: "POST", url: "getInventory.php", datatype: "json", data: ({skuSta ...

The back div is not retained on the second animation when flipping the card

In my card with a unique animation, clicking on the "Edit" button triggers the following actions: It smoothly transitions to the center of the screen. During this movement, it rotates by 180 degrees, revealing a blank green back content. Once the card r ...

Exploring the capabilities of AngularJS for efficient testing using Jasmine alongside mixpanel integration

Within my AngularJS application, I implement MixPanel for analytics by using the asynchronous script in my index.html file. index.html <script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script ...

When the chart is zoomed in, Highcharts displays points outside the chart area when hovering over the line

I recently began working with highcharts and for my current project, I need a prototype chart that allows zooming in and out. Specifically, I want to display the y-axis value in the tooltip only when the user hovers directly over the points. However, in hi ...

Verify the presence of a GET parameter in the URL

Working on a simple log in form for my website using Jade and ExpressJS. Everything is functioning correctly, except for one issue - handling incorrect log in details. When users input wrong information, they are redirected back to the log in page with a p ...

Getting access to a variable on the client side using express-expose

I'm looking to assign a JavaScript variable on my index.html page once it's returned by express.js. I've attempted to utilize the express-expose middleware, but I'm struggling to figure out how to set the variable in the static HTML pag ...

Looping Angular Components are executed

I am currently developing an Angular application and encountering an issue with my navbar getting looped. The problem arises when I navigate to the /home route, causing the navbar.component.html components to duplicate and appear stacked on top of each oth ...

What is causing the error message "Uncaught TypeError: Cannot read property 'helpers' of undefined" to occur in my straight-forward Meteor application?

As I follow along with the tutorial here, I encounter an issue after replacing the default markup/code with the provided HTML and JavaScript. The error message "Uncaught TypeError: Cannot read property 'helpers' of undefined" appears. Below is t ...

Developing an interactive contact page using bootstrap technology

I am looking for a way to structure my contact page using Bootstrap. https://i.sstatic.net/e3TCu.png If you're interested, the code for this layout can be accessed here: https://codepen.io/MatteCrystal/pen/xxXpLmK <div class="container" ...

Grouped Data Tables by Specific Dates

Hey, I'm working with a MySQL Table ID Number Date Created Name of Person File Titles 1 2021-10-11 12:00:00 OG Loc God Rap 2 2021-10-11 12:00:00 Ryder God Weedo 3 2021-10-10 12:00:00 Carl God Child 4 2021-10-10 12:00:00 Johnson God Cheat ...

Is there a way to retrieve the width and height of a parent element within a nested declaration in SASS?

Is there a way for a child element to automatically adopt the dimensions of its parent? How can I retrieve the width and height values of the parent element in order to achieve this effect? Here is an example code snippet: .thumb { width: 120px; ...

Alert: Refs cannot be assigned to function components. Any attempt to access this ref will result in failure. Have you considered using React.forwardRef()? displayed in the @Mui Component

Is anyone familiar with this particular component? <Controller control={control} {...register("DOB", {})} render={({ field }) => ( <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker ...

Attempting to squeeze a container with a set width into a parent element that spans the entire width of the screen (100

As I embark on my coding journey, I am faced with the challenge of creating a website that features full-width (100%) containers with fixed-width containers nested inside. Despite my efforts to experiment with both figures and divs, I have not been success ...

What is the best way to showcase a lengthy webpage similar to that of dzone.com?

Upon visiting dzone.com, it is evident that all the posts are displayed on a single page. As we scroll down the page, older posts are dynamically added to the end of the page while posts at the beginning are potentially removed from view. I am curious abo ...

Is it possible to utilize jQuery to insert a chosen form into a table?

Here is the code example I am working with: <label for="">Select Ticker: </label> <select class="form-control" style="display: inline" id='selected'> {% for p in tickers %} <option value="{{ p.tick ...

Calculating and Manipulating Numbers with JQuery in Bootstrap 4's Nav-Tabs Component

I found myself exploring the BootStrap documentation on nav-tabs, but to my dismay, I couldn't find a straightforward method to count the number of nav-items within a nav-tabs class. BootStrap Nav/Tabs After scouring StackOverflow and various online ...

Extract all nested array object values in JavaScript without including a specific key value

I am looking for a way to remove a specific key value pair within a nested array object in JavaScript. The goal is to get all the objects in the array after the removal. Can someone help me with this? In the following object, I want to remove the mon key ...

SOLVED: How to utilize CSS to confine scrollbars within nested div elements

As a novice in web programming, I am currently working on a userscript to add hotkeys to a website. I am using Firefox on Linux for this project, focusing solely on desktop functionality. Right now, my main focus is on enhancing the pop-up help view, which ...

Implementing CSS in Laravel 8

After placing my CSS file in the public/css folder, I included it in the head section with the following code. <link href="{{ url('/css/app.css') }}" rel="stylesheet"> Unfortunately, the CSS styles are not being applied ...

Interactive Navigation Bar in JavaScript

Is there a way to create a horizontal menu with an arrow that follows the mouse cursor? I saw this effect on a website (http://cartubank.ge) and I'm curious if anyone has the source code for it? Your help would be greatly appreciated. ...