Skip to content

Make basic accordian #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Accordion/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- style -->
<link rel="stylesheet" href="style.css" />
<title>Accordion</title>
</head>
<body>
<main>
<!-- top heading -->
<h1>Frequently Asked Questions</h1>

<!-- accordion -->
<div class="accordion">
<!-- item 1 -->
<div class="accordion__item">
<div class="accordion__head">
<h2 class="accordion__title">What is Netflix?</h2>
<img class="accordion__icon" src="plus.svg" alt="icon" />
</div>
<div class="accordion__body">
<p class="accordion__line">
Netflix is a streaming service that offers a wide variety of
award-winning TV shows, movies, anime, documentaries and more – on
thousands of internet-connected devices.
</p>
<p class="accordion__line">
You can watch as much as you want, whenever you want, without a
single ad – all for one low monthly price. There's always
something new to discover, and new TV shows and movies are added
every week!
</p>
</div>
</div>

<!-- item 2 -->
<div class="accordion__item">
<div class="accordion__head">
<h2 class="accordion__title">How much does Netflix cost?</h2>
<img class="accordion__icon" src="plus.svg" alt="icon" />
</div>
<div class="accordion__body">
<p class="accordion__line">
Watch Netflix on your smartphone, tablet, Smart TV, laptop, or
streaming device, all for one fixed monthly fee. Plans range from
₹ 149 to ₹ 649 a month. No extra costs, no contracts.
</p>
</div>
</div>
</div>
</main>

<!-- script -->
<script src="script.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions Accordion/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Accordion/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function accordionClickHandler(i) {
const currentOpenedAccordion = document.querySelector(".accordion--open");
currentOpenedAccordion?.classList.remove("accordion--open");
const clickedAccordion = document.querySelectorAll(".accordion__item")[i];
clickedAccordion.classList.toggle("accordion--open");
}

window.onload = () => {
const accordionItem = document.querySelectorAll(".accordion__head");
accordionItem.forEach((item, i) => {
item.addEventListener("click", () => {
accordionClickHandler(i);
});
});
};
89 changes: 89 additions & 0 deletions Accordion/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
width: 100%;
height: 100vh;
color: white;
background-color: black;
}

main {
width: 100%;
height: 100%;
display: flex;
gap: 0.5rem;
flex-direction: column;
align-items: center;
justify-content: center;
}

h1 {
font-size: 2rem;
font-weight: 700;
text-align: center;
}

.accordion {
max-width: 1150px;
display: flex;
gap: 0.5rem;
padding: 1rem;
flex-direction: column;
}

.accordion__item {
background-color: #2d2d2d;
}

.accordion__head {
cursor: pointer;
padding: 1.5rem;
display: flex;
gap: 1rem;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid black;
transition: all 500ms;
}

.accordion__head:hover {
background: #404040;
}

.accordion__title {
font-size: 1.5rem;
}

.accordion__icon {
width: 2.25rem;
height: 2.25rem;
object-fit: contain;
}

.accordion__body {
padding: 2rem;
display: none;
gap: 1.5rem;
flex-direction: column;
align-items: center;
justify-content: center;
transition: all 500ms;
}

.accordion__line {
font-size: 1.5rem;
}

.accordion--open .accordion__icon {
transform: rotateZ(45deg);
}

.accordion--open .accordion__body {
padding: 2rem;
visibility: visible;
display: flex;
}