Adaptive navigation bar dynamically incorporates links into the dropdown menu

Just a heads up, I'm pretty new to Bootstrap so bear with me. I tried creating a responsive menu with Bootstrap 4 and it seemed simple at first. However, I encountered an issue with my navbar when resized. Here's how it looks initially:

https://i.sstatic.net/xaFNp.jpg

But when I resize it, this is what happens:

https://i.sstatic.net/K2sd7.jpg

And then, upon clicking the dropdown menu, it turns into this:

https://i.sstatic.net/akUEy.jpg

I want the button to remain on the right side without being drawn into the menu. It's really confusing why this is occurring. Here's the code snippet I used:

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

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

  <button class="navbar-toggler order-first" type="button" data-toggle="collapse" data-target="#navbarNavDropdown">
                <span class="navbar-toggler-icon"></span>
            </button>

  <div class="collapse navbar-collapse ml-auto justify-content-end" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item"><a class="nav-link" href="#">Link 1</a></li>
      <li class="nav-item"><a class="nav-link" href="#">Link 2</a></li>
      <li class="nav-item"><a class="nav-link" href="#">Link 3</a></li>
    </ul>
  </div>
  <a class="btn btn-outline-info" href="#">Button</a>

</nav>

Your assistance is greatly appreciated!

Answer №1

Utilize the order-* classes to ensure that the navbar-collapse remains at the end on smaller screens.

<nav class="navbar fixed-top navbar-light navbar-expand-lg navbar-template">
    <a class="navbar-brand" href="#">Brand</a>
    <button class="navbar-toggler order-first" type="button" data-toggle="collapse" data-target="#navbarNavDropdown">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse ml-auto justify-content-end order-last order-lg-0" id="navbarNavDropdown">
        <ul class="navbar-nav">
            <li class="nav-item"><a class="nav-link" href="#">Link 1</a></li>
            <li class="nav-item"><a class="nav-link" href="#">Link 2</a></li>
            <li class="nav-item"><a class="nav-link" href="#">Link 3</a></li>
        </ul>
    </div>
    <a class="btn btn-outline-info" href="#">Button</a>
</nav>

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


Bootstrap NavBar with left, center or right aligned items

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 stopping links in iOS web applications from launching in a new Safari tab

I am in the process of developing an HTML application specifically for iPads. To enhance user experience, I have added the web app to the homescreen using the "favorite" option. However, I encountered an issue where every internal URL opens in a new Safari ...

Effortlessly automate clicking with JavaScript or HTML - learn how now!

Does anyone know how to automatically click a button on a page when it loads? I attempted using this JavaScript code, but it didn't work. <a href="javascript:Clickheretoprint()" id="print"> <script type="text/javascript"> $(document).rea ...

Issue with pre-selected checkboxes: JavaScript

A function was created to automatically check the first value of a checkbox when a page is loaded: function defaultCheck(){ document.checkBoxForm.list[0].checked = true; var val=document.checkBoxForm.list[0].value; showtotal[0] = docum ...

HTML containers continue to show gaps even with no margin or padding applied

I have a basic setup here with a single line of red text on a colored background. Despite setting margin and padding to zero and not having any child elements causing spacing issues, I still see a gap around my container. Here's my CSS: { width: ...

Exploring Bootstrap's Product sample and attempting to understand the process of incorporating images

Currently, I am utilizing Bootstrap 4 and taking advantage of their Product example as a foundation: https://getbootstrap.com/docs/4.4/examples/product/ My goal is to transform the white and gray background sections into actual images of the product. The ...

Can a custom wrapper be set as the default for content within the <router-outlet>?

Currently, my app.component.html is well-organized: <app-header></app-header> <router-outlet></router-outlet> <app-footer></app-footer> The output resembles this structure: <body> <app-header> ...

Is it possible to create two distinct homepages for a single website?

I'm currently working on a project where I am creating a replica of the website Make My Trip This website has different layouts for laptop and mobile devices, appearing completely different. How can we achieve this kind of functionality? Here is the ...

The reverse is concealed following a CSS flip transition

After applying a CSS flip animation to a card, the backside isn't visible once flipped. Here is the HTML code for the card component named "ptree-card": <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <!-- Rest of th ...

What is the best way to trigger one of two different functions randomly when an HTML button is clicked?

Is there a way to have an HTML button trigger one of two functions randomly on click event? I’m utilizing PHP on the server side and jQuery on the client side. I've tried using the following code but nothing happens when I click the button image... ...

Transform a flexbox child into a complete row that is wider than the container

I'm currently in the process of developing a portfolio section using Bootstrap 4 and delving into flexbox knowledge. Each item in the portfolio starts with a thumbnail that can be expanded or collapsed to reveal more details when clicked. When the vi ...

The alignment of divs can be disrupted in a Nested Grid system

I am working with a 16 grid system where I have two 8 column divs positioned side by side. In one of the 8 column divs, I am trying to include a 5 column div on the left and two three columns divs stacked on top of each other on the right. I have tried v ...

Designing a solid sidebar of a specific width alongside a flexible container for content that adapts to different screen sizes using

I have a sidebar that is fixed at 200px on the left side of the page, and a responsive content container on the right side. To center the content in the right container, I used the following CSS: .sidebar { width: 10%; position: fixed; height: 100%; bac ...

What is the reason behind Chrome's fullscreen mode turning the background black?

I created a webpage with full-screen functionality and made sure to use the correct CSS properties to ensure that my gradient background covers the entire screen perfectly. However, I encountered an issue when clicking the full-screen button in Chrome - th ...

Trouble with Bootstrap 5 Carousel swipe functionality: Issues arise when inner elements with overflow are involved, causing vertical scrolling to interfere with left to right swipes

I've been scouring the internet for answers to my unique issue with a Bootstrap 5 carousel. My setup is fairly basic, but I've removed the buttons and rely solely on swiping to navigate through the carousel items. When I swipe left to right, eve ...

Adjust size of background image to fit within ie8 window dimensions

Currently, I'm facing an issue where a Drupal 7 module is used to load a background image, but CSS3 resizing is not supported in IE8. background-image: url('image.jpg'); background-size: cover; I have tried conventional methods like placin ...

The color of hyperlinks in firefox varies based on the specific URL being visited

I am a beginner in the world of html and css. I have two links placed consecutively. In my css file, I have defined classes for a:link and a:hover. However, I noticed that the second link is displaying a purple color instead of silver. Both links correctly ...

Automatically numbering text boxes upon pressing the enter key

Is there a way to automatically number textboxes when I type "1" and hit enter in one of them? For example, if I have 3 textboxes and I type "1" in the first one, can the other textboxes be numbered as 2 and 3 accordingly? <input type="text&qu ...

Using JavaScript to swap between multiple images can be a powerful tool, but sometimes the wrong image

I'm having an issue with duplicating an image swap function. The problem is that the mouseout event is triggering image 3 on each of the three swaps, when I actually want it to trigger only on the last one. Can anyone provide some guidance on how to m ...

What is the most efficient way to transfer information from a text box in one form to another in AngularJS?

I am currently using a sample form to send data, and I would like to redirect this data to another page named result.html. Could you please guide me on how to achieve this? The code snippet below shows what I have implemented so far in the main page... ...

Creating a Vue.js transition that causes an icon to slide upwards along with an expanding panel

My goal is to implement a panel that expands from the bottom of the screen when an icon is clicked. I am utilizing Vue.js transition for animating the panel sliding in from below. However, I encountered an issue where the icon instantly jumps to its final ...