Toggle navigation
☰
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html> <head> <title>Responsive Navbar Example</title> <style> body { font-family: sans-serif; margin: 0; } .navbar { background-color: #2c3e50; display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; } .navbar-brand { color: white; font-size: 1.5em; font-weight: bold; text-decoration: none; } .nav-links { list-style: none; margin: 0; padding: 0; display: flex; gap: 15px; } .nav-links li a { color: white; text-decoration: none; padding: 10px 15px; display: block; } .nav-links li a:hover { background-color: #34495e; border-radius: 4px; } /* Mobile Layout */ @media (max-width: 600px) { .navbar { flex-direction: column; align-items: flex-start; padding: 0; } .navbar-brand { padding: 15px 20px; } .nav-links { flex-direction: column; width: 100%; gap: 0; /* Remove the gap so items touch */ } .nav-links li { width: 100%; } .nav-links li a { padding: 15px 20px; border-top: 1px solid #3b536b; /* Clear separation for stacked links */ border-radius: 0; /* Remove rounded corners */ } } </style> </head> <body> <nav class="navbar"> <a href="#" class="navbar-brand">Logo</a> <ul class="nav-links"> <li><a href="#">Home</a></li> <li><a href="#">Products</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <p style="padding: 20px;">Try resizing your browser window! The navbar will switch from a horizontal row to a vertical stacked list on smaller screens.</p> </body> </html>