I am trying to remake this: https://www.w3schools.com/bootstrap/bootstrap_theme_company.asp
The thing is, I don't want to just copy this example, I want to make it my own by changing certain parts (after first 100% remaking it).
This is the end-result: https://www.w3schools.com/bootstrap/trybs_theme_company_full.htm#myPage
If you try to make the page smaller, you will see that the navbar changes to a button (consisting of 3 icon-bars on top of eachother) that you can click. Now I want to change this button so it has the following characteristics:
- If you hover on it, background should become white and the 3 icon-bars should become orange;
- If you click on the button, background should become white and the 3 icon-bars should become orange. So what I want is that when the navbar has collapsed it should have this orange/white color scheme. If it hasn't collapsed it should return to normal (unless it's been hovered on)
The problem is, nothing I have tried works.
Here is my relevant html:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#myPage">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="#about">ABOUT</a></li>
<li><a href="#services">SERVICES</a></li>
<li><a href="#portfolio">PORTFOLIO</a></li>
<li><a href="#pricing">PRICING</a></li>
<li><a href="#contact">CONTACT</a></li>
</ul>
</div>
</div>
</nav>
Here is my relevant cs:
.navbar {
margin-bottom: 0;
background-color: #f4511e;
z-index: 9999;
border: 0;
font-family: Montserrat, sans-serif;
font-size: 12px !important;
letter-spacing: 4px;
border-radius: 0;
}
.navbar li a, .navbar .navbar-brand {
color: #FFFFFF !important;
}
.navbar-nav li a:hover, .navbar-nav li.active a {
color: #f4511e !important;
background-color: #FFFFFF !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
color: #ffffff;
}
.navbar-toggle:hover {
background: white !important;
color: #F4511e !important;
}
.navbar-toggle:focus {
background: white !important;
color: #F4511e !important;
}
.navbar-toggle:hover .icon-bar {
background: #F4511e !important;
}
.navbar-toggle:focus .icon-bar {
background: #F4511e !important;
}
.navbar-toggle .icon-bar {
background: white !important;
}
The big problem I am having is that focus doesn't do what I want, because when I click the button and then click somewhere else it changes back to its standard color scheme. I understand why, because it's not active anymore and isn't being hovered.
So I need somethink like focus, but that's linked with the navbar being collapsed or not. Do you guys have any idea how to achieve this?
After searching around the internet I found this question: how to change navbar color when nav-toggle is clicked
It's almost the same question as I have, but I don't really understand what Alaksandar Jesus Gene did and I can't make it work. Can someone explain what he did (see below) and help me understand what I should change to make it work in my own example?
Solution code that I don't quite understand:
.navbar-yellow{
background-color: yellow !important;
}
$(".navbar-toggle").click(function(){
$("nav").toggleClass("navbar-yellow");
})
Any help/ideas is/are greatly appreciated.
Thanks in advance,