Tips on positioning a secondary navbar below a sticky navbar in Bootstrap 4

Currently, I am utilizing bootstrap 4 to create an application that features two navbars. Both of these navbars are intended to be fixed at the top, with the second navbar hiding as the user scrolls down.

Here is the HTML code for the navbars:

Navbar 1:

<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-custom-light">
    <div class="container-fluid">
        <div class="row w-100">
            .... (Code for Navbar 1)
        </div>
    </div>
</nav>

Navbar 2:

<nav class="navbar fixed-top navbar-expand-md bg-dark navbar-dark">
   .... (Code for Navbar 2)
</nav>

I am facing an issue where the two navbars overlap each other when the page is scrolled. You can see this problem by visiting this link: https://www.bootply.com/y8EfMpCMc4#.

I need assistance in properly positioning Navbar 2 below Navbar 1 with a fixed position (while also ensuring responsiveness). Specifically, Navbar 2 should collapse on small devices and align to the right of the Navbar 1's brand name "New Project".

Answer №1

For the first navbar, try using sticky-top instead of fixed-top, and make the second navbar static by eliminating fixed-top.

<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-custom-light"></nav>
<nav class="navbar navbar-expand-md bg-dark navbar-dark"></nav>

Check out the demonstration here:


Related:
Bootstrap 4 collapsing two navbars into one toggle button
Bootstrap 4 Multiple fixed-top navbars

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

tips for adjusting padding in bootstrap-vue select component

Having trouble customizing the options in a bootstrap-vue select component. I am looking to add padding on top. I have attempted to modify the "custom-select" class and the option tag, but have not found a solution yet. https://i.sstatic.net/KMvEU.png ...

Modifying the chart width in Chart.js: A step-by-step guide

After creating a chart using Chart Js, I encountered an issue where the chart did not fit within the specified width. Adjusting the attributes of canvas proved to be ineffective, specifically with regards to the width attribute. Despite changing the value, ...

Apply CSS styles to a group of elements retrieved from an object

How can I apply CSS properties to each element in a collection using jQuery? const cssProperties = { "color": "#555555", "font-weight": "bold", "text-align": "left" }; const $tdCollection = $("tr:first-child").find("td:nth-child(2)"); // Co ...

Collaborate on documents with fellow users on the Django platform

Summary of the app: The main focus of this application is to enable users to create projects and share uploaded files with others, based on permission settings. Basically, after creating a project using the Project module, when a user uploads a file to the ...

Shrink image sizes using PHP

Currently I am trying to find a way to decrease the sizes of images using PHP when the page loads. Despite obtaining the dimensions, I am uncertain about how to proceed with reducing their sizes in PHP. Below is my existing code: <?php $stmt = $db-> ...

Leveraging the power of SCSS @extend within the <style> tag while importing global SCSS

After setting up my project using vue-cli, I incorporated both Bootstrap and Bootstrap-vue into it. To ensure that my theme.scss file is loaded correctly, I created a vue.config.js file and used the prependData option in the following manner: module.expor ...

Align content to the bottom using Bootstrap 4

Looking for help with aligning content to the middle and bottom on a full-page bootstrap layout? The first page has a background image in the first div, and a darker layer on top in the second div. <div class="h-100 w-100"> <div class="h-100 w-10 ...

Using the jQuery POST method to execute a redirect upon successful completion

I am attempting to utilize jQuery to create a post method. I have implemented it within a form and used bootstravalidator for validation. Once the form is successfully validated, it is posted and the PHP code comes into action. Now, my goal is to redirect ...

Animating UL/LI elements using the power of CSS3 transformations

I am interested in creating animations using CSS3 transitions. Let's consider the following UL/LI element: <ul> <li class="green" id="green" style="display: none;">Contents 1</li> <li class="red" id="red" style="display: ...

What is the reason for the delay in the firing of this document.ready event

Similar Question: Understanding window.onload vs document.ready in jQuery I seem to be encountering a problem: I have an image on my webpage that is relatively small. I also have a JavaScript function that dynamically sets the height of the left sideb ...

Is it recommended to employ @media print for a webpage dedicated exclusively to printing purposes?

Imagine a scenario where I have a specific page featuring a print button. Clicking on this button redirects me to a separate page with the same content, optimized for printing purposes. Instead of using @media print directly on the original page due to n ...

In CodeIgniter, the $this->input->post() function consistently returns an empty value

I'm encountering an issue where the value from an AJAX post always turns out empty. Even after confirming that the value is correct before the post, I'm unable to retrieve it using $this->input->post() HTML <?php if ($product_info-> ...

Customized pop-up alerts on web browsers

Is there a library available that provides notification features similar to those seen on Web Slack and Web Skype, allowing users to receive notifications even when they are not currently on the site page? https://i.sstatic.net/wANRg.png Thank you, and I ...

What is the best way to ensure that every item on a list can be

Is there a way to make both the left and right sides of a list item clickable? Currently, only the right side is clickable in my case. Any suggestions? This is my HTML: <body> <aside id = "aside"> <div id="column"> ...

How to use Vue.js to automatically redirect to a URL when a button is clicked

I have created a button that, when clicked, should redirect to a URL passed in it. Below is the code snippet: <template> <button type="button" v-on:click="gotosite(modalDetails.final.product_url)">Buy</button> </template> <s ...

Mastering the Art of Aligning Avatars: Effortless Right Alignment

Here's the updated version of the navigation bar: <nav class="navbar navbar-expand-md navbar-dark bg-dark static-top"> <button class="navbar-toggler" type="button" data-toggle="collapse"> ...

Steps for inserting new text in front of an element's existing text

Is there a way to insert text before the original content of an element? I know how to add text after using createTextNode, as shown in this example: $("#button").click(function() { $( ".text" ).append( document.createTextNode( " Hello" ) ); }); < ...

Utilize information stored in a database to automatically navigate to a different webpage

I am currently working with PHP, HTML, and a mySQL database. Here are my current project requirements: Retreive specific data from the database and output it. Compare this data with predetermined values. If the data falls outside of the specified range, ...

Tips for collapsing a child accordion when the parent accordion is collapsed?

Here is the code I have for a functional parent/child accordion div setup: <div class="accordion"> <h3>Part 1</h3> <div class="accordion"> <h3>Sub-Div1</h3> <div> <p>This ...

Utilize the <wbr> tag within FormattedMessage and assign it as a value while coding with TypeScript

Trying out the optional word break tag <wbr> in a message within <FormattedMessage id="some:message" />. Context Some words or texts are too lengthy for certain parent elements on smaller mobile screens, and we have a column layout t ...