imi36
imi36

Reputation: 49

Bootstrap Hamburger icon not visible

I'm totally novice in html/CSS, trying to make a simple web-page for an application. Can somebody advise me why the page unable to show the hamburger icon. I assumed it should be shown in white between the brand and start text. Here's the screenshot how it looks actually with the below script. Screenshot:

enter image description here

/* Modify the background color */

.navbar-custom {
  background-color: #004d99;
}


/* change the brand and text color */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: white;
}


/* change the link color */

.navbar-custom .navbar-nav .nav-link {
  color: white;
}


/* change the color of active or hovered links */

.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
  color: white;
}
<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

</head>
<nav class="navbar navbar-custom">
  <div>
    <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
           <span class="navbar-toggler-icon" style="color: white"></span><small><strong> START</strong></small>
         </button>
  </div>
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

Any help appreciated.

Upvotes: 2

Views: 1020

Answers (2)

Warden330
Warden330

Reputation: 1042

The Reason you cant see the Hamburger-button is because bootstrap hardcoded Icons as background-images to specific navbar-configurations. There are for example .navbar-light and .navbar-dark When you add Nav-Elements they get styled according to the navbar-scheme so the toggler for the hamburger is coded:

.navbar-dark .navbar-toggler-icon {
    background-image: url(data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E);
}

So a way to make this work with your code: Use the Navbar-class from bootstrap to configure the Element-style and use a custom background, see the example with added comments to the changes i made here:

/* Modify the background color */

/*changed class-name*/
.bg-custom {
  background-color: #004d99;
}


/* change the brand and text color */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: white;
}


/* change the link color */

.navbar-custom .navbar-nav .nav-link {
  color: white;
}


/* change the color of active or hovered links */

.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
  color: white;
}
<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

</head>
<!--changed navbar-class to basic bootstrap class-->
<nav class="navbar navbar-dark bg-custom">
  <div>
    <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
           <span class="navbar-toggler-icon" style="color: white"></span><small><strong> START</strong></small>
         </button>
  </div>
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

Or you have to add your own custom icon to the Toggler.

Upvotes: 2

Umutambyi Gad
Umutambyi Gad

Reputation: 4101

Insert an icon image between span tag here <span class="navbar-toggler-icon" style="color: white"></span> the following I tried to add my own icon but you can insert yours

Example

.navbar-custom {
  background-color: #004d99;
}


/* change the brand and text color */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: white;
}


/* change the link color */

.navbar-custom .navbar-nav .nav-link {
  color: white;
}


/* change the color of active or hovered links */

.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
  color: white;
}
<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  <style>

  </style>
</head>
<nav class="navbar navbar-custom">
  <div>
    <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
      <span class="navbar-toggler-icon" style="color: white"><img src="https://placehold.it/25x25/fc5"></span><small><strong> START</strong></small>
    </button>
  </div>
</nav>

Upvotes: 2

Related Questions