This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtask7.html
116 lines (103 loc) · 2.56 KB
/
task7.html
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
<!DOCTYPE html>
<html>
<head>
<title>Task 7</title>
<style>
.navbar {
background-color: lightblue;
border-radius: 10px;
padding: 10px;
display: flex;
}
.navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
display: flex;
align-items: center;
}
.navbar li {
margin-right: 10px;
}
.navbar a {
text-decoration: none;
color: black;
padding: 8px 12px;
border-radius: 5px;
}
.dropdown,
.dropdownclick {
position: relative;
display: inline-block;
}
.dropdown:hover,
.dropdownclick:hover {
background-color: orange;
}
.dropdown-content,
.dropdownc-content {
display: none;
position: absolute;
top: 27px;
background-color: lightblue;
border-radius: 10px;
padding: 10px;
box-shadow: 5px 5px bisque;
}
.dropdown:hover .dropdown-content,
.dropdownclick.active .dropdownc-content {
display: block;
background-color: beige;
}
.dropdown-content a,
.dropdownc-content a {
display: block;
padding: 5px;
border-radius: 5px;
transition: background-color 0.3s;
}
.dropdown-content a:hover,
.dropdownc-content a:hover {
background-color: pink;
}
</style>
</head>
<body>
<nav class="navbar">
<ul>
<li class="dropdown">
<a href="#">Hover</a>
<div class="dropdown-content">
<a>Profile</a>
<a>Coding Club</a>
<a>Repository</a>
</div>
</li>
<li class="dropdownclick">
<a href="#">Click</a>
<div class="dropdownc-content">
<a>Profile</a>
<a>Coding Club</a>
<a>Repository</a>
</div>
</li>
</ul>
</nav>
<script>
const dropdowns = document.querySelectorAll('.dropdownclick');
dropdowns.forEach((dropdown) => {
const dropdownContent = dropdown.querySelector('.dropdownc-content');
dropdown.addEventListener('click', function (event) {
this.classList.toggle('active');
event.stopPropagation();
});
document.addEventListener('click', function () {
dropdown.classList.remove('active');
});
dropdownContent.addEventListener('click', function (event) {
event.stopPropagation();
});
});
</script>
</body>
</html>