Skip to content

Commit 0bb6829

Browse files
committed
Accordian menu 📝
1 parent f099eb8 commit 0bb6829

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

17-accordion-menu/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>CSS - :focus-within pseudo class</title>
7+
<link rel="stylesheet" href="style.css" />
8+
<script src="main.js" defer></script>
9+
</head>
10+
<body>
11+
<div class="accordian">
12+
<!-- 1st -->
13+
<div class="container">
14+
<h3 class="title">Your Account</h3>
15+
<p class="content">
16+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
17+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
18+
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
19+
aliquip ex ea commodo consequat.
20+
</p>
21+
</div>
22+
23+
<!-- 2nd -->
24+
<div class="container">
25+
<h3 class="title">Payment & Pricing</h3>
26+
<p class="content">
27+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
28+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
29+
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
30+
aliquip ex ea commodo consequat.
31+
</p>
32+
</div>
33+
34+
<!-- 3rd -->
35+
<div class="container">
36+
<h3 class="title">Returns & Refunds</h3>
37+
<p class="content">
38+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
39+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
40+
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
41+
aliquip ex ea commodo consequat.
42+
</p>
43+
</div>
44+
</div>
45+
</body>
46+
</html>

17-accordion-menu/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const containers = document.getElementsByClassName("container");
2+
3+
// We can't directly apply forEach on the HTMLCollection, you have first convert them into an array
4+
Array.from(containers).forEach((container) => {
5+
container.addEventListener("click", () => {
6+
container.classList.toggle("is-active");
7+
});
8+
});

17-accordion-menu/style.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Fira+Code&family=Lato&display=swap");
2+
3+
* {
4+
margin: 0;
5+
padding: 0;
6+
box-sizing: border-box;
7+
font-family: "Lato", Fira Code, monospace;
8+
}
9+
10+
body {
11+
background-color: lavenderblush;
12+
margin: 0 40px;
13+
}
14+
15+
.accordian {
16+
height: 100vh;
17+
display: flex;
18+
flex-direction: column;
19+
justify-content: center;
20+
width: 700px;
21+
margin: 0 auto;
22+
}
23+
24+
.container {
25+
position: relative;
26+
}
27+
28+
.container .title {
29+
padding: 15px 24px;
30+
background-color: rgb(217, 216, 255);
31+
color: black;
32+
border-top-left-radius: 4px;
33+
border-top-right-radius: 4px;
34+
cursor: pointer;
35+
}
36+
37+
.container .content {
38+
display: flex;
39+
align-items: center;
40+
padding: 0 20px;
41+
height: 0px;
42+
margin-bottom: 20px;
43+
background-color: rgb(250, 250, 250);
44+
box-shadow: 0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1),
45+
0 0 0 1px rgba(10, 10, 10, 0.02);
46+
47+
border-bottom-left-radius: 4px;
48+
border-bottom-right-radius: 4px;
49+
transition: all 0.3s ease-in-out;
50+
overflow-y: auto;
51+
}
52+
53+
.container .title::before {
54+
content: "+";
55+
position: absolute;
56+
right: 20px;
57+
cursor: pointer;
58+
}
59+
60+
.container.is-active .content {
61+
height: 80px;
62+
}
63+
64+
.container.is-active .title::before {
65+
content: "-";
66+
}

0 commit comments

Comments
 (0)