Create a responsive two-line navigation bar

I am trying to create a responsive Bootstrap 3 navigation bar with two lines. However, I am having problems with the HTML structure and collapse functionality.

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

In essence, it is desirable to do the following:

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

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

Tablet / Desktop device:

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

Mobile device (wrinkled):

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

Mobile device (extended):

 |--------------------------------------| | LOGO/BRAND HAMBURGER | |--------------------------------------| | LinkA | | LinkB | | LinkC | | LinkD | | LinkE | |--------------------------------------| | Link1 | | Link2 | | Link3 | |--------------------------------------| 
+7
twitter-bootstrap twitter-bootstrap-3 navbar
source share
1 answer

If I had the html / css of your project, I use it to show how you should do it, but in this context THIS HTML came from a static Navbar example for Bootstrap v3.3.7

In fact, the idea puts <div id="navbar" class="navbar-collapse collapse"> in the line below <div class="navbar-header"> with a float and its width 100% of its place, then stretching <ul class="nav navbar-nav navbar-right"> using margin-top: -50px;

With this media query, we are confident that it will behave correctly in the 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 this worked or not.

+9
source share

All Articles