Search code examples
cssvue.jsbootstrap-4hamburger-menubootstrap-vue

Change hamburger icon color in Vue Bootstrap


I want to change the Vue Bootstrap Hamburger navbar-toggler-icon to a color of white.

I tried every combination of code I can think of without luck. When I load the app the CSS reverts back to the original bootstrap url. Any ideas?

This is what I am trying in the style section:

 .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(255, 255, 255, 255)") !important;
    }

Any ideas? Thanks,


Solution

  • You can use this CSS to change the color of the toggler. You can change the stroke on the <path> to the colour you want.

    If you are using a scoped style tag in your vue component (<style scoped>), then you might need to use a deep selector to properly target the toggle icon.

    .navbar-toggler-icon {
       background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='rgba(255, 255, 255, 1)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>") !important;
    }
    

    I found this specific CSS on the Bootstrap github here

    new Vue({
      el: '#app',
      data() {
        return {
          fields: [
            // A column that needs custom formatting
            { key: 'name', label: 'Full Name' },
            { key: 'age', label: 'Age' },
            { key: 'sex', label: 'Sex' }
          ],
          items: [
            { name: { first: 'John', last: 'Doe' }, sex: 'Male', age: 42 },
            { name: { first: 'Jane', last: 'Doe' }, sex: 'Female', age: 36 },
            { name: { first: 'Rubin', last: 'Kincade' }, sex: 'Male', age: 73 },
            { name: { first: 'Shirley', last: 'Partridge' }, sex: 'Female', age: 62 }
          ]
        }
      }
    })
    .navbar-toggler-icon {
       background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='rgba(255, 255, 255, 1)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>") !important;
    }
    <link href="https://unpkg.com/bootstrap@4.4.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="https://unpkg.com/bootstrap-vue@2.12.0/dist/bootstrap-vue.css" rel="stylesheet"/>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
    <script src="https://unpkg.com/bootstrap-vue@2.12.0/dist/bootstrap-vue.js"></script>
    
    <div id="app">
      <b-navbar toggleable="xl" type="dark" variant="info">
        <b-navbar-brand href="#">NavBar</b-navbar-brand>
    
        <b-navbar-toggle target="nav-collapse"></b-navbar-toggle>
    
        <b-collapse id="nav-collapse" is-nav>
          <b-navbar-nav>
            <b-nav-item href="#">Link</b-nav-item>
          </b-navbar-nav>
        </b-collapse>
      </b-navbar>
    </div>