Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create responsive Bootstrap navbar with two rows

I am trying to create a responsive Bootstrap 3 based navbar with two rows. However, I am having trouble with the structure of the HTML and the collapse functionality.

Below is a visual description of the desired result, and I was hoping someone could point me in the right direction in terms of HTML/CSS (with as much default Bootstrap functionality as possible).

Essentially the menu is desired to do the following:

  • On tablet/desktop devices, the first row is the logo and a menu of small secondary links (Link1-3). The second row is the main menu with main links (LinkA-E).

  • On mobile, the classic collapse design should appear with the logo and hamburger icon. The expanded menu should show the main links (LinkA-E) first, and then the secondary links (Link1-3) last.

Tablet/Desktop device:

|----------------------------------------------------------|
|  LOGO/BRAND                         Link1  Link2  Link3  |
|----------------------------------------------------------|
|  LinkA  LinkB  LinkC  LindD  LinkE                       |
|----------------------------------------------------------|

Mobile device (collapsed):

|--------------------------------------|
|  LOGO/BRAND               HAMBURGER  |
|--------------------------------------|

Mobile device (expanded):

|--------------------------------------|
|  LOGO/BRAND               HAMBURGER  |
|--------------------------------------|
|  LinkA                               |
|  LinkB                               |
|  LinkC                               |
|  LinkD                               |
|  LinkE                               |
|--------------------------------------|
|  Link1                               |
|  Link2                               |
|  Link3                               |
|--------------------------------------|
like image 427
preyz Avatar asked Dec 23 '16 12:12

preyz


People also ask

How do I add a button to The navbar in Bootstrap?

To add buttons inside the navbar, add the .navbar-btn class on a Bootstrap button: To add form elements inside the navbar, add the .navbar-form class to a form element and add an input (s). Note that we have added a .form-group class to the div container holding the input.

Is there a double row navbar with dropdown in Bootstrap?

Double Row Navbar with Dropdowns - Bootstrap 4 Code Snippet (2021) - Bootstrap Creative Double Row Navbar with Dropdowns Bootstrap Code Snippet. Quickly jumpstart your next project with this Bootstrap CSS compatible code samples. See Demo

How to extend or collapse a navigation bar in Bootstrap?

With Bootstrap, a navigation bar can extend or collapse, depending on the screen size. A standard navigation bar is created with the.navbar class, followed by a responsive collapsing class:.navbar-expand-xxl|xl|lg|md|sm (stacks the navbar vertically on xxlarge, extra large, large, medium or small screens).

How do I create a navigation bar in HTML?

A standard navigation bar is created with the .navbar class, followed by a responsive collapsing class: .navbar-expand-xxl|xl|lg|md|sm (stacks the navbar vertically on xxlarge, extra large, large, medium or small screens). To add links inside the navbar, use either an <ul> element (or a <div>) with class="navbar-nav".


1 Answers

If i had an html/css of your project i use it to show how you should do that, but in this context THIS HTML came from static navbar example of Bootstrap v3.3.7

actualy the idea is placing <div id="navbar" class="navbar-collapse collapse"> in row below <div class="navbar-header"> with floating and width it 100% of its space, then pulling up <ul class="nav navbar-nav navbar-right"> with margin-top: -50px;

With that media query we would sure it behave right in moblie device.

HTML

<div class="container-fluid">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">Logo/Brand</a>
  </div>
  <div id="navbar" class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li><a href="#">LinkA</a></li>
      <li><a href="#">LinkB</a></li>
      <li><a href="#">LinkC</a></li>
      <li><a href="#">LinkD</a></li>
      <li><a href="#">LinkE</a></li>
    </ul>
    <ul class="nav navbar-nav navbar-right">
      <li><a href="#">Link1</a></li>
      <li><a href="#">Link2</a></li>
      <li><a href="#">Link3</a></li>
    </ul>
  </div><!--/.nav-collapse -->
</div>

CSS

.navbar-collapse {
    float: left;
    width: 100%;
    clear: both;
}

@media (min-width: 768px) {
    .navbar-right {
        margin-top: -50px;
    }
}

JUST Let me know if it worked or not.

like image 66
mohamad faramarzi Avatar answered Sep 20 '22 11:09

mohamad faramarzi