Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force hamburger menu in Bootstrap 3.3.7 even for Desktop?

My code looks the same as this page:

https://getbootstrap.com/docs/3.3/examples/navbar/

When I open the page in mobile, it looks like this:

enter image description here

But when I open it on Desktop, it looks like this:

enter image description here

How can I force the page to look the same on Desktop as it does on Mobile?

i.e. I want a hamburger menu on the desktop version of the site.

Things I have tried

  • I set a max-width=480px on the outer div on the page, but that didn't help.

  • I have also posted a related question on the softwarerecs SE (https://softwarerecs.stackexchange.com/questions/51989/a-css-framework-which-is-essentially-a-mobile-only-unresponsive-version-of-boo), which BTW I think is silly (libraries are intrinsic to programming and library questions should be allowed on SO!).

like image 636
Alex R Avatar asked Sep 07 '18 00:09

Alex R


People also ask

Should you use hamburger menu on desktop?

Hamburger menus might be a great solution for mobile devices with limited screen space, however, translating the same mobile-first design into your desktop without any changes may cause a bad user experience. Putting your most important pages in hidden navigation could sabotage them.

Does bootstrap have a hamburger menu?

Hamburger Menu in Bootstrap is defined as a list of links or buttons or content on the navigation bar hidden or shown simultaneously when we click a button like a triple equal on the right side of the navigation bar. Hamburger menu is nothing but navigation bar.

How do I change the burger icon in bootstrap?

The hamburger toggler color is controlled by the two inbuilt classes used for changing the color of the content in the navigation bar: . navbar-light: This class is used to set the color of the navigation bar content to dark.

How do you open a burger menu?

A Hamburger Menu is a way to display navigation links on a website, usually for mobile devices and smaller screens. However, CSS hamburger menus can be used for desktop websites as well. Once you click the “hamburger” icon, a sliding menu will appear, displaying on top of the main content.


1 Answers

Here's a css-only example. Full credit to the original author.

HTML

<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-header">
    <a class="navbar-brand" href="#">Brand</a>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
  <div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#about">About</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
    <div class="navbar-header navbar-right">
        <p class="navbar-text">
        <a href="#" class="navbar-link">Username</a>
        </p>
    </div>
  </div>
</nav>

CSS

body {
    padding-top:70px;
}

.navbar-header {
  float: none;
}
.navbar-toggle {
  display: block;
}
.navbar-collapse.collapse {
  display: none!important;
}
.navbar-nav {
  float: none!important;
}
.navbar-nav>li {
  float: none;
}
.navbar-collapse.collapse.in{
  display:block !important;
}
like image 88
djnz Avatar answered Oct 14 '22 01:10

djnz