-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdown_menu2.html
More file actions
59 lines (51 loc) · 1.3 KB
/
dropdown_menu2.html
File metadata and controls
59 lines (51 loc) · 1.3 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
<div class="dropdown">
<button class="dropdown-btn">Select an Option ▼</button>
<div class="dropdown-content">
<a href="#">Option 1</a>
<a href="#">Option 2</a>
<a href="#">Option 3</a>
</div>
</div>
<script>
document.querySelector(".dropdown-btn").addEventListener("click", function () {
document.querySelector(".dropdown-content").classList.toggle("show");
});
window.onclick = function (e) {
if (!e.target.matches('.dropdown-btn')) {
document.querySelector(".dropdown-content").classList.remove("show");
}
};
</script>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-btn {
background: #3498db;
color: white;
padding: 10px;
border: none;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
background: white;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
min-width: 150px;
transition: 0.3s;
}
.dropdown-content.show {
display: block;
}
.dropdown-content a {
display: block;
padding: 10px;
color: black;
text-decoration: none;
}
.dropdown-content a:hover {
background: #ddd;
}
</style>