Liz
Liz

Reputation: 1457

Change Bootstrap Hamburger Color Only on Collapse

I'm using bootstrap to have a see-through nav when the page first opens, but as soon as the user scrolls down and the navbar collapses it changes to a white background.

I use this to make the background color change:

.top-nav-collapse {
  background-color: #FFFFFF !important;
}

And I know from extensive Googling that this changes the color of the hamburger icon in general:

.navbar-default .navbar-toggle .icon-bar {
  background-color: black;
}

However, I can't seem to get the color to change only on collapse. Here's my nav bar code:

    <nav class="navbar  navbar-fixed-top z-depth-1" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
                    <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 waves-effect waves-light pull-left" href="/"><%= image_tag 'Flame.png', style: "height: 100%"%></a>
            </div> <!-- navbar-header -->

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
                <ul class="nav navbar-nav">
                    <li><a href="#" class="waves-effect waves-light">Workouts <span class="sr-only">(current)</span></a></li>
                    <li><%= link_to 'Blog', posts_path, class:"waves-effect waves-light" %></li>
                    <li><a href="#" class="waves-effect waves-light">Equipment</a></li>
                    <li><a href="#" class="waves-effect waves-light">About Us</a></li>
                </ul>
            </div> <!-- navbar collapse -->
        </div> <!-- container-fluid -->
    </nav>

Can anyone shed any light on this?

Upvotes: 0

Views: 4237

Answers (1)

jeffjenx
jeffjenx

Reputation: 17487

Difficult to completely understand what you're asking, but I think you're just looking for this

.navbar-toggle.collapsed .icon-bar {
  ...
}

If you use as-is, you might need to !important any properties to override the Bootstrap defaults. Otherwise add any necessary specificity (i.e. #main-nav .navbar-toggle...) to the selector and you should be good.

Upvotes: 1

Related Questions