Responsive Bootstrap 4 navigation bar featuring collapsible menu and various elements displayed on the right side

I have been struggling for quite some time to create a mobile menu using Bootstrap 4. My goal is to display the 3 brand names and the toggle button on the same row in the mobile menu. However, when I click the toggle button, the 3 brands end up below the collapsed menu. I want the 3 brands to remain at the top in a single row along with the toggle button even after the menu collapses. The issue lies in the fact that the collapsing menu is taking up 100% of the column width, which is causing the 3 brands to be pushed down below the menu. Any assistance would be greatly appreciated.

Solution Objective

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

HTML Code

<body id="page-top">
 <nav class="navbar navbar-dark bg-primary navbar-fixed-top">
  <div class="container">

    <button class="navbar-toggler hidden-md-up pull-xs-right" data-target="#collapsenav" data-toggle="collapse" type="button">
            ☰
        </button>
    <div class="row">
        <div class="col-md-6 col-sm-12 col-xs-12">
             <div class="navbar-toggleable-sm collapse  text-xs-center" id="collapsenav">
                <ul class="nav navbar-nav">
                  <li class="nav-item"><a class="nav-link" href="#">About</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Resume</a></li>
                </ul>
            </div>
        </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-1</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-2</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-3</a>
      </div>
    </div>
  </div>
</nav>   
</body> 

Access this example on CodePen

Answer №1

Discover the latest Bootstrap 4 alpha 6 flexbox utilities for effortless alignment and uncomplicated markup:

<nav class="navbar navbar-toggleable-sm navbar-inverse bg-primary fixed-top">
    <div class="container">
        <div class="d-flex w-100 justify-content-between flex-last">
            <button class="navbar-toggler align-self-end mb-1" data-target="#collapsenav" data-toggle="collapse" type="button">
                ☰
            </button>
            <div class="d-flex w-100 flex-first justify-content-between">
                <a class="navbar-brand" href="#home">Brand-1</a>
                <a class="navbar-brand" href="#home">Brand-2</a>
                <a class="navbar-brand" href="#home">Brand-3</a>
            </div>
        </div>
        <div class="navbar-collapse collapse w-100" id="collapsenav">
            <ul class="nav navbar-nav align-items-center">
                <li class="nav-item active"><a class="nav-link" href="#">About</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Resume</a></li>
            </ul>
        </div>
    </div>
</nav>

Check out the demo here

This current version of alpha 6 has a reported bug where a container inside the navbar reduces in width on smaller screens. This issue will be addressed in the beta release, but for now, some simple CSS adjustments can ensure the inner container remains full-width on mobile devices.

@media (max-width:767px) {
    .container {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

Answer №2

Should the 3 brands be positioned on the right side?

If you want to have the brands aligned to the left using Bootstrap, simply rearrange the nav-brand links between the button and the divs that contain the navigation list content. This adjustment will ensure that your 3 brands remain in place without being pushed down.

<body id="page-top">
 <nav class="navbar navbar-dark bg-primary navbar-fixed-top">
  <div class="container">
 <button class="navbar-toggler hidden-md-up pull-xs-right" data-target="#collapsenav" data-toggle="collapse" type="button">
            ☰
        </button>
    //place brand items here
    <a class="navbar-brand" href="#home">Brand-1</a>
    <a class="navbar-brand" href="#home">Brand-2</a>
    <a class="navbar-brand" href="#home">Brand-3</a>
    <div class="row">
        <div class="col-md-6 col-sm-12 col-xs-12">
             <div class="navbar-toggleable-sm collapse  text-xs-center" id="collapsenav">
                <ul class="nav navbar-nav">
                  <li class="nav-item"><a class="nav-link" href="#">About</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Resume</a></li>
                </ul>
            </div>
        </div>
    //remove these out
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-1</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-2</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-3</a>
      </div>
    </div>
  </div>
</nav>   
</body> 

In case you require the three brands to be displayed on the right side, you may need to implement some custom bootstrap CSS modifications. This involves showcasing the brands on large screens as initially coded, and hiding them on smaller screens while displaying the added code snippet above for better alignment.

<body id="page-top">
 <nav class="navbar navbar-dark bg-primary navbar-fixed-top">
  <div class="container">
 <button class="navbar-toggler hidden-md-up pull-xs-right" data-target="#collapsenav" data-toggle="collapse" type="button">
            ☰
        </button>
        //display these on small screens
        <a class="navbar-brand" href="#home">Brand-1</a>
        <a class="navbar-brand" href="#home">Brand-2</a>
        <a class="navbar-brand" href="#home">Brand-3</a>
        <div class="row">
           <div class="col-md-6 col-sm-12 col-xs-12">
             <div class="navbar-toggleable-sm collapse  text-xs-center" id="collapsenav">
                <ul class="nav navbar-nav">
                  <li class="nav-item"><a class="nav-link" href="#">About</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
                  <li class="nav-item"><a class="nav-link" href="#">Resume</a></li>
                </ul>
            </div>
        </div>
    //reveal these below on large screens
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-1</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-2</a>
      </div>
      <div class="col-md-2 col-sm-4 col-xs-4">
          <a class="navbar-brand" href="#home">Brand-3</a>
      </div>
    </div>

I am still learning coding, so I hope this provides some assistance!

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

"Enhance your website with dynamic drop-down menus using

Currently, I am working on creating a dynamic menu using Twitter Bootstrap by loading JSON files that contain the menu items. The structure of the JSON file looks like this: // test.json { "children": [ { "text": "Item1", "children": [ ...

Utilize AJAX JQuery to Transmit POST Data

I am facing an issue with sending the selected item from a Bootstrap dropdown to my controller using the POST method. Unfortunately, I am encountering difficulties in getting it to work. Within the dropdown, I am fetching records from the database and dis ...

Switch the CSS class when clicking on a responsive table within a table

I am looking to update the background color of a row within a table when a tr is clicked. Below is the code for the table: <div class="table-responsive"> <table class="table table-hover"> <thead> ...

Mobile Image Sizing with Bootstrap 4 Cards

I am currently developing a responsive web application using Bootstrap 4 and incorporating cards with images on one of the pages. The layout functions properly when resizing the window on desktop view; however, upon viewing it on mobile devices, I noticed ...

How can I extract the text within a Span tag using Selenium WebDriver?

Is there a way to retrieve the text from a span tag and print it using Selenium Webdriver? I am looking to extract the text UPS Overnight - Free The HTML code is as follows: div id="customSelect_3" class="select_wrapper">> <div class="select ...

Aligning the stars with CSS

One of the components I have deals with a star rating system, and I thought it would be cool to use Font Awesome icons for half stars. Everything is working well except for the CSS styling aspect. While I managed to position some of the stars correctly by ...

Can two div elements be positioned next to each other without relying on CSS float?

Every time I try to use CSS float to align two elements next to each other on a webpage, IE and Firefox always throw unexpected surprises my way. Is there an alternative method to position two divs side by side on a website without relying on CSS float? ...

Splitting the text vertically by utilizing a single DOM element

I am searching for a way to split my text vertically, with line breaks so that only one word should be present on each line. Currently, I have achieved this by using separate DIV elements for each word. Is it possible to accomplish the same layout using ...

Tips for assigning an AngularJS value to jQuery

Displaying a value in a view using {{ myvalue }}. Assigning the value from the controller as $scope.myvalue = "123"; Attempting to send this value myvalue to an ajax call. Need to assign angularjs value to jquery value. How can I accomplish assigning t ...

Using JQuery to Customize Navigation Menu Targeting

On my website, I am trying to make an href button and a menu fade in as the page loads. However, I am struggling to find the correct code due to its placement within multiple tags, especially since I am new to JS and JQuery. I have provided a fiddle with a ...

Tips for getting a browser to clear the cache specifically for the .html files on your website

After making updates to a client's website, I'm encountering an issue where the browser is displaying a cached version of the site. The website consists of static .html files. Although clearing my browser's cache resolves the issue for me, I ...

Ineffectiveness of Less Guard feature

I have a mixin with a guard clause that I've implemented following the provided guidelines. According to the syntax below, @palette should be selected from a list of custom colors and @color should be assigned a value from a specific set. The curren ...

Is Consistency Possible with CSS Transition Direction?

Take a look at this example: https://codepen.io/jon424/pen/XWzGNLe In the provided code snippet, there is a button that can toggle the visibility of an image. When clicked, the image disappears from bottom to top and reappears when clicked again. The use ...

Animate CSS backward when hovered

I am having trouble with getting an animation to play in reverse when hovering over an element. No matter what I try, it just snaps back to the beginning without any smooth transition. Interestingly, this issue only occurs in Chrome and Safari browsers. ...

NodeJS allows for seamless uploading of files

I'm encountering difficulties when trying to upload a file using nodeJS and Angular. I've come across some solutions, but they all involve Ajax which is unfamiliar territory for me. Is there a way to achieve this without using Ajax? Whenever I ...

Stopping Accordion Title from Moving Vertically in Material-UI

Just finished creating this accordion which will be used as a menu item. However, I've encountered an issue where clicking on the Main title causes the accordion summary to move downward vertically. Any suggestions on how to keep the Main tile fixed ...

"Embedding a Highcharts web chart within a pop-up modal window

I am looking to incorporate a Highcharts web chart onto a specific part of a Bootstrap modal, while ensuring the size remains dynamic along with the modal itself. Here's what I have attempted so far: Sample HTML code: <td><a href="#">${ ...

Is it possible for me to designate a specific class for the rev value?

<a href="img1.jpg" rel="zoom-id:bike" rev="img1.jpg"> <img src="" class="img-thumb"/></a> Shown above is a snippet of HTML code. I wonder if it's possible for the attribute rev="img1.jpg" to have a class that only affects the s ...

Troubleshooting issues with media queries related to device pixel ratio

My media queries in LESS are functioning correctly on the desktop, but encountering issues when tested on an iPad2 or Samsung Galaxy 4 phone. It appears that the device-pixel-ratio is causing disruptions. I attempted to reduce the min-device-pixel-ratio to ...

Guide to personalizing the ngxDaterangepickerMd calendaring component

I need to customize the daterangepicker library using ngxDaterangepickerMd in order to separate the start date into its own input field from the end date. This way, I can make individual modifications to either the start date or end date without affectin ...