I’m introducing a responsive navbar to my site so the menu turns into a hamburger style menu that only appears when the screen size is less that 600 pixels wide.
I have the icon (embedded from font awesome) set to hidden until the screen size is 600 pixels or less. The function seems to work but I can’t get the icon to change color. It’s currently black and it’s sitting against a black background so you can’t see it when the conditions are met. Perhaps i’m not using the correct targetting in my code?
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "navbar") {
x.className += " responsive";
} else {
x.className = "navbar";
};
}
.navbar {
margin: 30px;
padding-left: 20px;
overflow: hidden;
background-color: #333;
border-radius: 25px;
}
a {
float: left;
display: block;
font-family: 'Anybody';
font-size: 1.5rem;
font-weight: 100;
color: beige;
text-align: center;
padding: 8px 20px;
margin: 5px 20px 5px 30px;
text-decoration: none;
}
a:hover {
background-color: #111;
}
a.active {
background-color: rgb(82, 90, 90);
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.navbar .icon {
display: none;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one. Show the link that contains
should open and close the topnav (.icon) */
@media screen and (max-width: 600px) {
.navbar a:not(:first-child) {
display: none;
}
/* this line hides the menu items except for the first one (first child) */
.navbar a.icon {
float: right;
display: block;
color: white;
border: solid white 1px;
}
}
/* The "responsive" class is added to the navbar with JavaScript when the user clicks on the icon. This class makes the navbar
look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
.navbar.responsive {
position: relative;
}
.navbar.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
}
<header>
<nav class="navbar" id="myTopnav">
<a href="./Home.html" class="active">Developer | Steven Llewellyn</a>
<a href="./Projects.html">Projects</a>
<a href="./Skills.html">Skills</a>
<a href="./Contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa-solid fa-bars fa-8x"></i>
</a>
</nav>
</header>
I have tried taking the icon element
<i class="fa-solid fa-bars"></i>
out of the nav bar and trying to style it on it’s own. When I style it like this it works:
<section class="skills-icons">
<i class="fa-brands fa-html5 fa-8x"></i> <!-- the size is controlled by the fa-10x-->
<i class="fa-brands fa-css fa-8x"></i>
<i class="fa-brands fa-js fa-8x"></i>
<span style="font-size: 3em; color: white; background-color: grey;">
<i class="fa-solid fa-bars"></i>
</span>
</section>
I have tried this inline styling in the navbar but it has no effect.

