-1

I am a novice at CSS, here's HTML structure:

<nav id="navbar" class="navbar navbar-expand-sm">
    <a class="navbar-brand ml-4" href="#">
        <img src="images/logo-light.svg" alt="" width="30" height="90" class="d-inline-block align-top" id="navlogo">
    </a>
    <button class="navbar-toggler collapsed border-0" id="navbar-toggler" type="button">
        <span> </span>
        <span> </span>
        <span> </span>
    </button>
</nav>

What I need to do is if I add a class "black" to navbar I need the css background color on navbar-toggler to turn white. How do I do that with CSS?

I thought it should be like:

. navbar .black .navbar-toggler span{
    background: #000 !important;
}

but it's not working

jac
  • 55
  • 1
  • 6

2 Answers2

1

You were very close.

By going .navbar .black, you are targeting .black that is inside .navbar. But by doing .navbar.black you are targeting the element that has both .navbar and .black.

.navbar.black .navbar-toggler span{
    background: #FFF!important;
}
Sean
  • 936
  • 4
  • 15
0

you can use javascript addEventListener

const nav = document.querySeletor('#navbar)
('#navbar_toggler').addEventListener('toggle',function(){
    nav.classList.toggle('bg')
  
})
.bg{
background-color:black;
}
Ajinkya
  • 57
  • 3