Skip to content

Commit

Permalink
finish dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sql-fan committed Dec 28, 2024
1 parent 24ef5db commit a38575f
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions dropdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Javascript dropdown module
7 changes: 7 additions & 0 deletions dropdown/dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const dropdownContent = document.querySelector('.dropdown-content');
const dropdownBtn = document.querySelector('.dropdown-btn');

dropdownBtn.addEventListener('click', () => {
console.log(dropdownContent.className);
dropdownContent.classList.toggle('visible');
});
32 changes: 32 additions & 0 deletions dropdown/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dropdown</title>
<link rel="stylesheet" href="style.css" />
<script defer src="dropdown.js"></script>
</head>
<body>
<nav>
<a class="nav-item" href="#">Home</a>
<a class="nav-item" href="#">News</a>
<div class="dropdown">
<button class="nav-item dropdown-btn">Dropdown</button>
<div class="dropdown-content">
<a href="#">item-1</a>
<a href="#">item-2</a>
<a href="#">item-3</a>
<a href="#">item-4</a>
<a href="#">item-5</a>
</div>
</div>
</nav>
<main>
<div>
<h1>Dropdown example</h1>
<p>Hover....</p>
</div>
</main>
</body>
</html>
12 changes: 12 additions & 0 deletions dropdown/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "dropdown-js",
"version": "1.0.1",
"main": "dropdown.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "av97",
"license": "MIT",
"description": ""
}
69 changes: 69 additions & 0 deletions dropdown/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, Helvetica, sans-serif;
height: 100vh;
display: flex;
flex-direction: column;
}
nav {
margin: 6px;
background-color: rgb(229, 134, 10);
display: flex;
align-items: center;
justify-content: end;
}

main {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
text-align: center;
background-color: slategray;
color: white;
}
.dropdown {
position: relative;
display: inline-block;
}

.nav-item {
padding: 12px;
cursor: pointer;
border: none;
width: 150px;
font-size: 20px;
background-color: inherit;
text-align: center;
}

.nav-item:hover {
background-color: red;
}

.dropdown-content {
display: block;
position: absolute;
width: 100%;
background-color: #f1f1f1;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.visible {
background-color: red;
display: none;
}

a {
text-decoration: none;
color: black;
padding: 12px;
display: block;
text-align: left;
}

0 comments on commit a38575f

Please sign in to comment.