Search code examples
htmlcssbootstrap-4navbar

Icon bar burger not working and displaying only one horizontal line


I'm trying to create a responsive layout button that looks like this:

enter image description here

But the problem is that I'm not being able to create the three horizontal lines, only one of them. Staying this way:

enter image description here

My code:

HTML

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
   <span class="navbar-toggler-icon"></span>
</button>

CSS

.navbar-toggler {
  position: relative;
  float: right;
  width: 40px;
  height: 40px;
  margin-top: 5px;
  margin-right: 5px;
  cursor: pointer;
  z-index: 99999;
}

.navbar-toggler span {
  height: 4px;
  background: #545454;
  transition: 0.2s all;
}

.navbar-toggler span:before, .navbar-toggler span:after {
  content: "";
  display: block;
}

Solution

  • You can use the HTML unicode &#9776; for hamburger icon

    You can find more at here: https://www.w3schools.com/charsets/ref_utf_symbols.asp

    .navbar-toggle
    {
    font-size:25px; 
    background:none; 
    border:none;
    }
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">&#9776;                 
    </button>

    You can also animate the icon see: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_menu_icon_js