-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathnavbar.html
More file actions
121 lines (105 loc) · 2.48 KB
/
Copy pathnavbar.html
File metadata and controls
121 lines (105 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!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>
/* --- Basic Reset --- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
/* --- Navbar Styling --- */
nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #0d6efd;
color: white;
padding: 1rem 2rem;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
}
.nav-links {
display: flex;
gap: 1.5rem;
list-style: none;
transition: all 0.3s ease;
}
.nav-links li a {
text-decoration: none;
color: white;
font-weight: 500;
transition: color 0.2s ease;
}
.nav-links li a:hover {
color: #ffeb3b;
}
/* --- Hamburger Button --- */
.menu-toggle {
display: none;
background: none;
border: none;
color: white;
font-size: 1.8rem;
cursor: pointer;
}
/* --- Responsive Rules --- */
@media (max-width: 768px) {
.menu-toggle {
display: block;
}
.nav-links {
position: absolute;
top: 70px;
left: 0;
background-color: #0d6efd;
width: 100%;
flex-direction: column;
align-items: center;
display: none;
}
.nav-links.active {
display: flex;
}
.nav-links li {
padding: 1rem 0;
}
}
</style>
</head>
<body>
<!-- Navbar -->
<nav>
<div class="logo">MySite</div>
<button class="menu-toggle" id="menu-toggle">☰</button>
<ul class="nav-links" id="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<!-- Dummy Content -->
<section style="padding: 2rem;">
<h1>Welcome to My Responsive Site!</h1>
<p>This is a sample page demonstrating a navbar that collapses into a hamburger menu on mobile screens.</p>
</section>
<!-- JavaScript -->
<script>
const toggleButton = document.getElementById('menu-toggle');
const navLinks = document.getElementById('nav-links');
toggleButton.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
</script>
</body>
</html>