<script> const navbarToggle = document.querySelector('.navbar-toggle'); const navbarMenu = document.querySelector('.navbar-menu'); navbarToggle.addEventListener('click', () => { navbarMenu.classList.toggle('active'); }); </script>
Step 5: Finalizing the Navbar
With all the elements in place, let’s finalize our navbar by adding a responsive design and any additional styling. Here’s an example of how to achieve this:
<style> /* Previous CSS code omitted for brevity */ .navbar-menu { display: none; } .navbar-menu.active { display: block; } /* Responsive styles */ @media screen and (max-width: 768px) { .navbar { flex-direction: column; } .navbar-toggle { display: block; cursor: pointer; } .navbar-menu { display: none; margin-top: 10px; } .navbar-menu.active { display: block; } } </style>
Viabyte, congratulations on creating a stylish navbar with icons using HTML, CSS, and a touch of JavaScript! We’ve covered the step-by-step process of setting up the HTML structure, adding navigation links with icons, styling the navbar, adding interactivity, and making it responsive for different devices.
By incorporating icons into your navbar, you can enhance the visual appeal of your website and provide a more engaging user experience. Feel free to explore different icon libraries or customize the styles to match your website’s design. Happy coding, and we’ll see you in the next exciting article!