Responsive Navigation Bar
HTML CODE :-
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512- DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> </head> <body> <header> <a href="#" class="logo"><i class="fa-solid fa-house"></i><span>Logo</span></a> <ul class="navlink"> <li><a href="#" class="active">Home</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Services</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Contact</a></li> </ul> <div class="menu"> <a href="#" class="login"><i class="fa-solid fa-user"></i><span>Login In</span> </a> <a href="#">Register</a> <div class="menu-icon"> <i class="fa-solid fa-bars" id="menu-icon"></i> </div> </div> </header> </body> </html> |
CSS CODE :-
body{ padding: 0px; margin: 0px; } header{ width: 100%; background-color:black; display: flex; align-items: center; justify-content: space-evenly; position: fixed; top: 0; right: 0; z-index: 1000; padding: 10px 2px; } .logo{ display: flex; align-items: center; } .logo i{ margin-right: 5px; font-size: 20px; color:#0bb502; } .logo span{ font-weight: bold; color: white; font-size: 20px; } a{ text-decoration: none; color: white; } .navlink{ display: flex; list-style: none; } .navlink a{ margin: 0 20px; } .navlink a:hover{ color:#0bb502; } .menu{ display: flex; align-items: center; } .menu a{ margin-right: 13px; margin-left: 10px; border: 2px solid whitesmoke; padding:8px; } .menu a:hover{ border: 2px solid #0bb502; } .login{ display: flex; align-items: center; } .login i{ margin-right: 5px; color:#0bb502; } .active{ font-weight: bold; } .menu-icon i{ cursor: pointer; display: none; color: white; font-size: 25px; } @media (max-width: 830px){ header{ padding: 2px 10px; } .navlink a{ margin: 0 10px; } } |
JS CODE :-
$(document).ready(function(){ $('#menu-icon').click(function(){ $('ul').toggleClass('show') }); }); |