<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Navbar</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
background-color: #f0f2f5;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
padding: 10px 20px;
color: white;
}
.navbar a {
color: white;
text-decoration: none;
padding: 10px;
font-size: 1em;
}
.navbar a:hover {
background-color: #575757;
border-radius: 5px;
}
.menu {
display: flex;
gap: 15px;
}
.menu-toggle {
display: none;
cursor: pointer;
font-size: 1.5em;
}
@media (max-width: 768px) {
.menu {
display: none;
flex-direction: column;
width: 100%;
background-color: #333;
position: absolute;
top: 60px;
left: 0;
padding: 10px 20px;
gap: 0;
}
.menu-toggle {
display: block;
}
.menu.show {
display: flex;
}
}
</style>
</head>
<body>
<header class="navbar">
<div class="brand">MySite</div>
<div class="menu-toggle" onclick="toggleMenu()">☰</div>
<nav class="menu" id="menu">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</nav>
</header>
<script>
function toggleMenu() {
const menu = document.getElementById('menu');
menu.classList.toggle('show');
}
</script>
</body>
</html>