Skip to content

Commit 14c1011

Browse files
committed
Custom Dropdown Added
1 parent 355fd90 commit 14c1011

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
| 37 | [Custom Date Input](https://github.com/sahilatahar/HTML-CSS-JavaScript/tree/main/custom-date-input) | [Live Demo](https://sahilatahar.github.io/HTML-CSS-JavaScript/custom-date-input/) |
4646
| 38 | [Social Media Card](https://github.com/sahilatahar/HTML-CSS-JavaScript/tree/main/social-media-card) | [Live Demo](https://sahilatahar.github.io/HTML-CSS-JavaScript/social-media-card/) |
4747
| 39 | [Microsoft Logo](https://github.com/sahilatahar/HTML-CSS-JavaScript/tree/main/microsoft-logo) | [Live Demo](https://sahilatahar.github.io/HTML-CSS-JavaScript/microsoft-logo/) |
48+
| 40 | [Custom Dropdown](https://github.com/sahilatahar/HTML-CSS-JavaScript/tree/main/custom-dropdown) | [Live Demo](https://sahilatahar.github.io/HTML-CSS-JavaScript/custom-dropdown/) |
4849

4950
### Disclaimer Regarding Ownership of this repository
5051

custom-dropdown/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Dropdown</title>
8+
<!-- Icon Scout Package -->
9+
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.8/css/line.css">
10+
<link rel="stylesheet" href="style.css">
11+
</head>
12+
13+
<body>
14+
<div class="container">
15+
<div class="dropdown">
16+
<div class="dropdown-main">
17+
<p class="dropdown-value">Select</p>
18+
<i class="uil uil-angle-down"></i>
19+
</div>
20+
<div class="dropdown-list">
21+
<div class="dropdown-item"><input type="radio" name="interest"> Web Development</div>
22+
<div class="dropdown-item"><input type="radio" name="interest"> Full Stack Development</div>
23+
<div class="dropdown-item"><input type="radio" name="interest"> Front End Development</div>
24+
<div class="dropdown-item"><input type="radio" name="interest"> Back End Development</div>
25+
</div>
26+
</div>
27+
</div>
28+
29+
<script src="script.js"></script>
30+
</body>
31+
32+
</html>

custom-dropdown/script.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const dropdownMain = document.querySelector('.dropdown-main'),
2+
dropdownList = document.querySelector('.dropdown-list'),
3+
dropdownItems = document.querySelectorAll('.dropdown-item'),
4+
dropdownValue = document.querySelector('.dropdown-value');
5+
6+
let options = ["Web Developer", "Full Stack Developer", "Front End Developer", "Back End Developer"];
7+
8+
let interest = 0;
9+
10+
dropdownMain.addEventListener('click', () => {
11+
dropdownList.classList.toggle('show');
12+
});
13+
14+
dropdownItems.forEach((item, index) => {
15+
item.addEventListener('click', (e) => {
16+
interest = index;
17+
console.log("clicked")
18+
dropdownValue.innerHTML = options[interest];
19+
item.children[0].checked = true;
20+
dropdownList.classList.remove('show');
21+
});
22+
});

custom-dropdown/style.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600&display=swap');
2+
3+
* {
4+
padding: 0;
5+
margin: 0;
6+
box-sizing: border-box;
7+
font-family: 'Rubik', sans-serif;
8+
}
9+
10+
body {
11+
min-height: 100vh;
12+
display: flex;
13+
justify-content: center;
14+
align-items: center;
15+
background-color: #5E6FB6;
16+
}
17+
18+
.dropdown {
19+
position: relative;
20+
user-select: none;
21+
-webkit-user-select: none;
22+
}
23+
24+
.dropdown-main,
25+
.dropdown-list {
26+
width: 250px;
27+
padding: .5rem 1rem;
28+
border-radius: .3rem;
29+
background-color: #fff;
30+
}
31+
32+
.dropdown-main {
33+
display: flex;
34+
justify-content: space-between;
35+
cursor: pointer;
36+
padding: .6rem 1rem;
37+
}
38+
39+
.dropdown-list {
40+
position: absolute;
41+
top: 110%;
42+
left: 0%;
43+
display: none;
44+
}
45+
46+
.dropdown-list.show {
47+
display: block;
48+
}
49+
50+
.dropdown-item {
51+
display: flex;
52+
gap: .5rem;
53+
padding: .3rem;
54+
cursor: pointer;
55+
}

0 commit comments

Comments
 (0)